/* begin common cookie functions. see http://techweb/javascript_commons/docs/cookies.html for documentation. */
/* Set cookie value */
function setCookie(name, value, escapeValue, expires, path, domain, secure) {

	var cookieToken = name + '=' + ((escapeValue) ? escape(value) : value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
	document.cookie = cookieToken;

}

/* Get cookie value */
function getCookie(name) {
	var allCookies = document.cookie;
	
	var cookieName = name + "=";
	var start = allCookies.indexOf("; " + cookieName);
	
	if (start == -1) {
		start = allCookies.indexOf(cookieName);
		if (start != 0) return null;
	}
	else start += 2;
	
	var end = document.cookie.indexOf(";", start);
	if (end == -1) end = allCookies.length;
	
	return unescape(allCookies.substring(start + cookieName.length, end));
}

/* Delete a cookie */
function deleteCookie(name, path, domain) {
	var value = getCookie(name);
	if (value != null) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
	return value;
}

/* Test for cookie support */
function verifyCookieSafe() {
	setCookie('pingCookies', 'hello');
	if (getCookie('pingCookies')) return true;
	else return false;
}

/* end common cookie functions. */

/* begin text size widget */
function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		a.disabled = true;
		if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
			) return a.getAttribute("title");
	}
	return null;
}

