/* cookie functions */

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));
}

// 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" : "");
}

// 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 */

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'body');
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
//Specify spectrum of different font sizes:
function checkCookie() {
	var tempVal = getCookie("fontSize");
	if(tempVal=="") {
		startSz = 1.1;
		setCookie("fontSize", startSz, getExpDate(360, 0, 0), "/");
//		setSize('body', startSz);
	} else {
		stringSz = getCookie("fontSize");
		startSz = parseFloat(stringSz);
		setSize('page', startSz);
		setDropdown('sizeSelection', startSz);
	}
}


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";
/*
	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 ];
	}*/
}
function setDropdown(elem, size) {
	var d = document.getElementById(elem);
	
	switch (size) {
		case .9:
		d.selectedIndex = 0;
		break;
		case 1:
		d.selectedIndex = 1;
		break;
		case 1.1:
		d.selectedIndex = 2;
		break;
		case 1.25:
		d.selectedIndex = 3;
		break;
		case 1.4:
		d.selectedIndex = 4;
		break;
		default: break;
	}

}
function changeText() {
	var select = document.getElementById('sizeSelection');
	var size = select.value + 'em';
	document.getElementById('page').style.fontSize = size;
	setCookie("fontSize", select.value, 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 ];
		}
	}
}


function openWin(theURL,winName,properties) {
 theWindow = window.open(theURL,winName,properties);
 theWindow.focus();
} //end function openWin()
