/*
	Easydynfont 
	Version 1.0
	written by Chris Heilmann
	please refer to the homepage at http://www.onlinetools.org/tools/easydynfont.php 
*/

// Standard setting, separate fonts with "," and make sure to set standardfont
// and size to avoid errors
var fonts="Tahoma, Verdana, Arial".split(",");
var standardfont="Tahoma, Verdana, Arial"
var standardsize="100%"
var nosave=false; 
function getDoc()
{
	var doc = document.getElementById("TableWrapperMiddle");
	if (doc==null)
	{
		doc= document.getElementById("TableWrapperMiddleRight");
	}
	if (doc==null)
	{
		doc= document.getElementById("TableWrapper");
	}

	return doc;
}

/* 
	function drawform()
	adds the standard form to the document.
*/
function drawform(){
    if (!document.layers){

		if (getDoc()!=null)
		{

	//	document.write("<fieldset id=\"txtprefs\">");
	//	document.write("<legend>");
	//	document.write("<img src=\"/images/h_textprefs.gif\" alt=\"text preferences utility\" width=\"89\" height=\"11\" class=\"himg\" \/>");
	//	document.write("<\/legend>");

			//document.write("<select class=\"dynselect\" name=\"typeface\" onchange=\"setFont(this.options[this.selectedIndex].value)\">");
	//		for (i=0;i<fonts.length;i++){
	//			document.write("	<option value=\""+fonts[i]+"\">"+fonts[i]+"<\/option>");
	//		}
	//		document.write("<\/select>");
		document.write("<a title=\"Decrease Font Size\" href =\"#\" onclick=\"addSize(-10)\">-<\/a>");
	//	document.write(" Text Size ");
		document.write("<a title=\"Reset Font Size\" href =\"#\" onclick=\"addSize(0)\">Text Size<\/a>");
		document.write("<a title=\"Increase Font Size\" href =\"#\" onclick=\"addSize(10)\">+<\/a>");
		document.write("&nbsp; |");
	//	document.write("<\/fieldset>");
		}
	}
}

function drawformRedesign(){
    if (!document.layers){
		document.write("&nbsp;&nbsp;&nbsp;I&nbsp;&nbsp;&nbsp;");
		document.write("<a title=\"Set to Base Text Size\" href =\"#\" onclick=\"addSize(0)\">");
		document.write("Text Size");
		document.write("<\/a>&nbsp;");
		document.write("<a title=\"Decrease Font Size\" href =\"#\" onclick=\"addSize(-10)\">");
		document.write("-");
		document.write("<\/a>&nbsp;");
		document.write("<a title=\"Increase Font Size\" href =\"#\" onclick=\"addSize(10)\">");
		document.write("+");
		document.write("<\/a>");
	}
}

/* 
	function init()
	loads the cookiedata and changes the document accordingly, if there is no 
	cookie, sets the standard settings and stores it 
*/

function init(){
    if (!document.layers){
	size=getCookie("dynfontsize");
	if (getDoc()!=null)
	{
		
		if (size!=null){
			c=size.split(":");
			getDoc().style.fontSize=c[0];
			//document.getElementsByTagName("body").item(0).style.fontFamily=c[1];
		}
		if (size==null || c[0]=="" || c[1]==""){
			getDoc().style.fontSize=standardsize;
			//document.getElementsByTagName("body").item(0).style.fontFamily=standardfont;
			storeSize()
			}
		}
	}
	// Special setting, if you want to use the "don't save" chekbox
	// nosave=document.dynform.nosave.checked
}		
/* 
	function addSize(add)
	increases the size of the document font by "add", negative values make the 
	font smaller.
*/
function addSize(add){
    if (!document.layers){
		if (getDoc()!=null)
		{
			if (add==0)
				{
				size = parseInt(standardsize);
				}
			else
				{
				size=parseInt(getDoc().style.fontSize)+add;
				}
			getDoc().style.fontSize=size+"%";
			if (nosave==false) storeSize()
		}
	}
}
/* 
	function SetSize(add)
	sets the font size of the document.
*/
function setSize(add){
    if (!document.layers){
	if (getDoc()!=null)
		{
			getDoc().style.fontSize=add+"%";
			if (nosave==false) storeSize() 
		}
	}
}

/* 
	function SetFont(add)
	sets the font face of the document.
*/
function setFont(add){
    if (!document.layers){
		if (getDoc()!=null)
			{
				getDoc().style.fontFamily=add;
				if (nosave==false) storeSize()
			}
	}
}

/* 
	function storeSize()
	saves the current settings of the document in a cookie
*/
function storeSize(){
	var exp = new Date();
	exp.setTime(exp.getTime() + 24*60*60*90*1000);
	size=document.getElementsByTagName("body").item(0).style.fontSize;
	font=document.getElementsByTagName("body").item(0).style.fontFamily;
	setCookie("dynfontsize",size+":"+font,exp);
}
/* 
	function setCookie()
	sets the cookie
*/
function setCookie(name, value, expires, path, domain, secure) { 
	var curCookie = name + "=" + escape(value) + 
	((expires) ? "; expires=" + expires.toGMTString() : "") + 
	((path) ? "; path=" + path : "") + 
	((domain) ? "; domain=" + domain : "") + 
	((secure) ? "; secure" : "") 
	document.cookie = curCookie 
} 
/* 
	function getCookie()
	reads the cookie
*/
function getCookie(name) { 
	var prefix = name + "=" 
	var cookieStartIndex = document.cookie.indexOf(prefix) 
	if (cookieStartIndex == -1) 
	return null 
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + 
	prefix.length) 
	if (cookieEndIndex == -1) 
	cookieEndIndex = document.cookie.length 
	return unescape(document.cookie.substring(cookieStartIndex + 
	prefix.length, 
	cookieEndIndex)) 
} 


