var newsCookie;
var newsCookieName = 'wowdNewsCookie';

function toggleNews(id, pos, show) {
	var big = document.getElementById('news_' + id);
	var small = document.getElementById('mini_' + id);
	if (big != null && small != null) {
		big.style.display = show ? '' : 'none';
		small.style.display = show ? 'none' : '';
	}
	if (newsCookie != null) {
		newsCookie[pos] = (show ? 1 : 0);
		setcookie(newsCookieName, newsCookie.join(' '));
	}
}

function prepareCookies() {
	var tempString = getcookie(newsCookieName);
	if (!tempString) {
		tempString = '';
		var elem = document.getElementsByTagName('TABLE');
		for (var i = 0; i < elem.length; i++) {
			att = elem[i].getAttribute("class");
			if (att == "newsmini") {
				var value = (elem[i].style.display == '') ? '0' : '1';
				tempString += value + ' ';
			}
		}
		setcookie(newsCookieName, tempString);
	}
	// Apply cookie settings to categories.
	newsCookie = tempString.split(" ");
	var elem = document.getElementsByTagName('TABLE');
	var pos = 0;
	for (var i = 0; i < elem.length; i++) {
		var att = elem[i].getAttribute("class");
		if (att == "newsmini") {
			var name = elem[i].getAttribute("id");
			var style = elem[i].style.display;
			if (((style == 'none') && (newsCookie[pos] == 0)) ||
				((style == '') && (newsCookie[pos] == 1))) {
				toggleNews(name.substr(5), (newsCookie[pos] == 1));
			}
			pos++;
		}
	}
}

function getexpirydate(nodays) {
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime(nomilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
	var cookiestring = "" + document.cookie;
	var index1 = cookiestring.indexOf(cookiename);
	if ((index1 == -1) || (cookiename == "")) {
		return "";
	}
	var index2 = cookiestring.indexOf(';', index1);
	if (index2 == -1) {
		index2 = cookiestring.length;
	}
	return unescape(cookiestring.substring(index1 + cookiename.length + 1,index2));
}

function setcookie(name, value){
	cookiestring = name + "=" + escape(value) + ";EXPIRES=" + getexpirydate(365) + ";PATH=/";
	document.cookie = cookiestring;
}
