/* cookie functions */

//Specify spectrum of different font sizes:
function checkCookie() {
	var tempVal = getCookie("fontSize");
	if(tempVal=="" || tempVal==null) {
		startSz = 1.1;
		setCookie("fontSize", startSz, getExpDate(360, 0, 0), "/");
//		setSize('body', startSz);
	} else {
		stringSz = getCookie("fontSize");
		startSz = parseFloat(stringSz);
		setSize('wrapper', startSz);
	}
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}
// utility function called by getCookie()
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/* textSizer functions */
function setSize( trgt,startSz ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	startSz = sz;
	setCookie("fontSize", startSz, getExpDate(360, 0, 0), "/");

	if ( !( cEl = d.getElementById( trgt ) ) ) 
		cEl = d.getElementsByTagName( trgt )[ 0 ];
		
	var currentSize = (cEl.style.fontSize).toString();

	if (currentSize != (sz).toString() + "em")
		cEl.style.fontSize = sz + "em";
}
function changeText(element) {
	var size = 1.1;
	if (element == 'small') size = 1.1;
	if (element == 'normal') size = 1.27;
	if (element == 'large') size = 1.45;
	document.getElementById('wrapper').style.fontSize = size + 'em';
	setCookie("fontSize", size, getExpDate(360, 0, 0), "/");
	
}
function ts( trgt,inc ) {
	if (document.getElementById) 
	{
		var d = document,cEl = null,sz = startSz,i,j,cTags;
		sz += inc;
		if ( sz < 0 ) sz = 0;
		if ( sz > 6 ) sz = 6;
		startSz = sz;
		setCookie("fontSize", startSz, getExpDate(360, 0, 0), "/");
		if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	
		cEl.style.fontSize = szs[ sz ];
	
		for ( i = 0 ; i < tgs.length ; i++ ) {
			cTags = cEl.getElementsByTagName( tgs[ i ] );
			for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
		}
	}
}
