function changeStyle(e) {
	var object;
	if(window.event)
		object = event.srcElement;
	else
		object = e.target;
		
		
	if (object.className == 'subOff')
		object.className = 'subOver';
	else if (object.className != 'subOn')
		object.className = 'subOff';
}

function load(url) {
	if(getCookie('WEBSESSION', 'ID'))
		document.location.href = url;
	else
		if(url.indexOf('?') > 0)
			document.location.href = url + '&websessionid=' + websessionid;
		else
			document.location.href = url + '?websessionid=' + websessionid;
}

function getCookie(name, subname) {
	var cookie = document.cookie; 
	var index = cookie.indexOf(name + "=");
	
	if (index == -1) return null;
	index = cookie.indexOf("=", index) + 1; 
	var endstr = cookie.indexOf(";", index);
	if (endstr == -1) endstr = cookie.length;
	cookie = cookie.substring(index, endstr);
	if (subname) {
		index = cookie.indexOf(subname + "=");
		if (index == -1) return null;
		index = cookie.indexOf("=", index) + 1; 
		endstr = cookie.indexOf("&", index);
		if (endstr == -1) endstr = cookie.length;
		cookie = cookie.substring(index, endstr);
	}
	
	return unescape(cookie);
}

function writeCookie(name, value) {
	var cCookie;
	var date = new Date();
	var newDate = new Date((date.getFullYear()+1),date.getMonth(),date.getDate());
	cCookie = name + '=' + value + '; path=/';
	document.cookie = cCookie;
}

function removeFromCookie(name,string) {
	var cookie = getCookie('CNPVotes');
	writeCookie(name,cookie.replace(string,''));
}

function initPage() {
	//Check if we support cookies otherwise try to add it to href
	if (null == getCookie('WEBSESSION', 'ID'))
		for(i=0; i<document.links.length; i++) {
			if(document.links[i].href.substring(0,4)=='http')
				if(document.links[i].href.indexOf('?') > 0)
					document.links[i].href += '&websessionid=' + websessionid;
				else
					document.links[i].href += '?websessionid=' + websessionid;
		}
}

function popup(url, width, height, scrollbars, extras) {
	if(extras!=null)
		extras = ',' + extras;
	else
		extras = ',' + 'locationbar=0,menubar=0,statusbar=0,toolbar=0,status=0,location=0,resizable=no';
	newwin = window.open(url, '','width=' + width +',height=' + height + ', scrollbars=' + scrollbars + extras);
	newwin.focus();
}

function setFormValue(form, item, value) {
	document.forms[form].elements[item].value = value;
}

function setFormFocus(form, item) {
	document.forms[form].elements[item].focus();
}

function uniDecode(str) {
	//Convert 2-byte chars to one byte (needed because Microsoft Internet Explorer cannot handle Unicode strings in JavaScript)
	var re;
	re=/Ã/g;
	str=str.replace(re, "Ü");
	re=/Ã¼/g;
	str=str.replace(re, "ü");
	re=/Ã/g;
	str=str.replace(re, "É");
	re=/Ã©/g;
	str=str.replace(re, "é");
	re=/Ã¥/g;
	str=str.replace(re, "å");
	re=/Ã/g;
	str=str.replace(re, "Ö");
	re=/Ã/g;
	str=str.replace(re, "Ä");
	re=/Ã¶/g;
	str=str.replace(re, "ö");
	re=/Ã/g;
	str=str.replace(re, "Å");
	re=/Ã¤/g;
	str=str.replace(re, "ä");
	re=/Ã/g;
	str=str.replace(re, "Ø");
	re=/Ã¸/g;
	str=str.replace(re, "ø");
	re=/Ã/g;
	str=str.replace(re, "Æ");
	re=/Ã¦/g;
	str=str.replace(re, "æ");
	
	return str;
}

