function createR()
{
	var ro;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}

	return ro;
}

var http = createR();
var lang = null;
var calendarDays = new Array ();
var monthNames = new Array ('januar', 'februar', 'marec', 'april', 'maj', 'junij', 'julij', 'avgust', 'september', 'oktober', 'november', 'december');
var activeProgressBar = null;
var bookmarkNodeOpen = null;
var bookmarkSectionNodeOpen = null;

function sndReq (action, data)
{
	http.open ('get', '/inc/rpc.php?action=' + action + '&data=' + data);
	http.onreadystatechange = handleResponse;
	http.send(null);
//	alert('/inc/rpc.php?action=' + action + '&data=' + data);
}

function handleResponse ()
{
	if (http.readyState == 4)
	{
		if (http.status == 200)
		{
			var response = http.responseText;
			var update = new Array();

			if ((response.indexOf('||') != -1))
			{

				update = response.split ('||');
				if (update[0] == 'poll')
				{
					var el = document.getElementById ('pollFrame');

					DLwrapper = document.createElement ("DL");
					DLwrapper.className = "poll-resuts";

					el.appendChild (DLwrapper);

					list = update[1].split ('|');
					var sum = 0;

					for (var n = 0; n < list.length; n++)
					{
						tmp = list[n].split ('::');
						DTwrapper = document.createElement("DT");
						DTContent = document.createTextNode(tmp[1]);
						DTwrapper.appendChild(DTContent);

						DDwrapper = document.createElement("DD");
						barImg = document.createElement("IMG");
						barImg.src = '/dsg/default/backgrounds/poll-bar.gif';
						barImg.id = 'pollBar' + n;
						barImg.height = 10;

						percentSpan = document.createElement("SPAN");
						percentSpan.id = 'pollPer' + n;
						percentSpan.innerHTML = '&nbsp;0%';

						DDwrapper.appendChild(barImg);
						DDwrapper.appendChild(percentSpan);

						DLwrapper.appendChild(DTwrapper);
						DLwrapper.appendChild(DDwrapper);
						sum+= parseInt (tmp[2]);
						pollArr[n] = tmp[2];
					}

					totals = document.createElement("SMALL");
					totals.innerHTML = '(Skupaj vseh glasov: ' + sum + ')';

					el.removeChild (document.getElementById('pollLoader'));
					el.appendChild (totals);

					for (var n in pollArr)
					{
						pollArr[n] = Math.round ((pollArr[n] / sum) * 100);
					}

					slideVote (0);
				}
				else if (update[0] == 'radar')
				{
					tmp = update[1].split ('::');

					if (tmp[0] == 'OK')
					{
						var el = document.getElementById ('radarButton' + tmp[2]);
						slika = document.createElement("IMG");
						if (tmp[1] == 1)
						{
							slika.src = '/dsg/sl/buttons/radar_odjavi.gif';
						}
						else
						{
							slika.src = '/dsg/sl/buttons/radar_prijavi.gif';
						}
						el.replaceChild(slika,el.childNodes[0]);
					}
				}
				else if (update[0] == 'delRadar')
				{
					tmp = update[1].split ('::');

					if (tmp[0] == 'OK')
					{
						var el = document.getElementById ('radarItem_' + tmp[1]);
						el.parentNode.removeChild (el);
					}
				}
				else if (update[0] == 'bookmark')
				{
					var el = document.getElementById ('favButton');

					if (update[1] == 'OK')
					{
						el.innerHTML = '<div class="shadow-button"><p class="large"><span>Clanek je dodan med priljubljene</span></p></div>';
					}
					else
					{
						el.innerHTML = '<div class="shadow-button"><p class="large"><span>Failed!</span></p></div>';
					}
				}
				else if (update[0] == 'bookmarkEdit')
				{
					tmp = update[1].split ('::');
					bmId = tmp[0];

					if (bookmarkNodeOpen != null)
					{
						tmpEl = document.getElementById (bookmarkNodeOpen);
						tmpEl.parentNode.removeChild (tmpEl);
						bookmarkNodeOpen = null;
					}

					if (bookmarkSectionNodeOpen != null)
					{
						eltmp = document.getElementById ('bookmarkSectionInput_' + bookmarkSectionNodeOpen);
						tmpS = eltmp.value;
						eltmp.parentNode.removeChild (eltmp);
						document.getElementById ('bookmarkSectionTitle_' + bookmarkSectionNodeOpen).innerHTML = tmpS;
						bookmarkSectionNodeOpen = null;
					}

					var bm = document.getElementById ('bookmarkNode_' + bmId);
					var bmSection = document.getElementById ('bookmarkSectionId_' + bmId).value;

					bmDiv = document.createElement ("DIV");
					bmDiv.id = 'bookmarkEdit_' + bmId;
					bmDiv.className = 'editline';

					bmDL = document.createElement ("DL");
					bmDiv.appendChild (bmDL);

					bookmarkNodeOpen = 'bookmarkEdit_' + bmId;

					bmDD = document.createElement ("DT");
					bmDD.innerHTML = 'Nova rubrika: ';
					bmDL.appendChild (bmDD);

					bmSelect = document.createElement ("SELECT");
					bmSelect.id = 'bookmarkEditSelect_' + bmId;

					bmSelect.options[0] = new Option ('root', 0);

					cnt = 1;
					cntSel = 0;
					for (i = 1; i < tmp.length; i++)
					{
						section = tmp[i].split('|');
						bmSelect.options[cnt] = new Option (section[1], section[0]);
						cntSel = (bmSection == section[0]) ? cnt : cntSel;
						cnt++;
					}
					bmSelect.selectedIndex = cntSel;

					bmDD = document.createElement ("DD");
					bmDD.appendChild (bmSelect);
					bmDL.appendChild (bmDD);

					bmA = document.createElement ("a");
					bmImg = document.createElement("img");
					bmImg.src = "/dsg/sl/buttons/osvezi.gif";
					bmA.appendChild (bmImg);
					bmA.href = 'javascript:void(0);';
					bmA.onclick = function () {updateBookmark (bmId);};

					bmDD = document.createElement ("DD");
					bmDD.appendChild (bmA);

					bmDL.appendChild (bmDD);
					bmClear = document.createElement ("div");
					bmClear.className = 'clear';
					bmClear.innerHTML = '&nbsp;';
					bmDiv.appendChild (bmClear);

					bm.appendChild (bmDiv);
				}
				else if (update[0] == 'bookmarkDelete')
				{
					tmp = update[1].split ('::');
					if (tmp[1] == 'OK')
					{
						var bm = document.getElementById('bookmarkNode_' + tmp[0]);
						bm.parentNode.removeChild (bm);
					}
					else
					{
						alert ('Prišlo je do napake.');
					}
				}
				else if (update[0] == 'bookmarkUpdate')
				{
					tmp = update[1].split ('::');
					if (tmp[0] == 'OK')
					{
						var bmE = document.getElementById('bookmarkEdit_' + tmp[1]);
						bmE.parentNode.removeChild (bmE);
						bookmarkNodeOpen = null;

						var bm = document.getElementById('bookmarkNode_' + tmp[1]);

						if (tmp[2] == 0)
						{
							var bmSection = document.getElementById('tree');
							bmSection.appendChild (bm);
							bm.setAttribute('style', 'padding:5px 0;margin:0;');
							document.getElementById ('bookmarkSectionId_' + tmp[1]).value = '0';

						}
						else
						{
							var bmSection = document.getElementById('bookmarkSectionNode_' + tmp[2]);
							bmSection.appendChild (bm);
							bm.removeAttribute('style');
							document.getElementById ('bookmarkSectionId_' + tmp[1]).value = tmp[2];
							expandToItem ('tree', 'bookmarkNode_' + tmp[1]);
						}
					}
					else
					{
						alert ('Prišlo je do napake.');
					}
				}
				else if (update[0] == 'bookmarkSectionDelete')
				{
					tmp = update[1].split ('::');
					if (tmp[1] == 'OK')
					{
						var bm = document.getElementById('bookmarkSectionParent_' + tmp[0]);
						bm.parentNode.removeChild (bm);
					}
					else
					{
						alert ('Prišlo je do napake.');
					}
				}
				else if (update[0] == 'bookmarkSectionUpdate')
				{
					tmp = update[1].split ('::');
					if (tmp[0] == 'OK')
					{
						var bmE = document.getElementById('bookmarkSectionInput_' + tmp[1]);
						bmE.parentNode.removeChild (bmE);

						var bm = document.getElementById('bookmarkSectionTitle_' + tmp[1]);
						bm.innerHTML = tmp[2];

					}
					else
					{
						alert ('Prišlo je do napake.');
					}

					bookmarkSectionNodeOpen = null;
				}
				else if (update[0] == 'bookmarkSectionNew')
				{
					tmp = update[1].split ('::');
					if (tmp[0] == 'OK')
					{
						el = document.getElementById ('tree');

						lastNode = null;
						for (var itemi=0; itemi < el.childNodes.length; itemi++)
						{
							var item = el.childNodes[itemi];
							if (item.nodeName == 'LI')
							{
								for (var sitemi=0; sitemi < item.childNodes.length; sitemi++)
								{
									var sitem = item.childNodes[sitemi];
									if (sitem.nodeName=="UL")
									{
										lastNode = item.id;
									}
								}
							}
						}

						newSection = document.createElement ('LI');
						newSection.id = 'bookmarkSectionParent_' + tmp[1];
						newSection.className = nodeClosedClass;

						newSectionSpan = document.createElement('SPAN');
						newSectionSpan.className = nodeLinkClass;
						newSectionSpan.appendChild (document.createTextNode("\u00A0"));
						newSectionSpan.onclick = function () {newSection.className = (newSection.className == nodeOpenClass) ? nodeClosedClass : nodeOpenClass; return false;};
						newSection.appendChild (newSectionSpan);

						newSectionName = document.createElement('SPAN');
						newSectionName.id = 'bookmarkSectionTitle_' + tmp[1];
						newSectionName.appendChild (document.createTextNode (tmp[2]));
						newSection.appendChild (newSectionName);
						newSection.appendChild (document.createTextNode("\u00A0"));

						nsEdit = document.createElement('A');
						nsEdit.href = 'javascript:void(0)';
						nsEdit.onclick = function () {editBookmarkSection (tmp[1])};
						nsEdit.appendChild (document.createTextNode('edit'));
						newSection.appendChild (nsEdit);
						newSection.appendChild (document.createTextNode("\u00A0"));

						nsDelete = document.createElement('A');
						nsDelete.href = 'javascript:void(0)';
						nsDelete.onclick = function () {removeBookmarkSection (tmp[1])};
						nsDelete.appendChild (document.createTextNode('delete'));
						newSection.appendChild (nsDelete);

						newSection.appendChild (document.createElement('UL'));

						el.insertBefore(newSection, document.getElementById (lastNode).nextSibling);
						document.getElementById('bookmarkSectionNew').value = '';
					}
					else
					{
						alert ('Prišlo je do napake ali pa rubrika že obstaja.');
					}
				}
				else if (update[0] == 'quote')
				{
					tmp = update[1].split ('::');
					document.getElementById ('commentContent').value = '[QUOTE=' + tmp[0] + ']' + tmp[1] + '[/QUOTE]' + "\n";
					commentContent = true;
					document.getElementById ('commentContent').focus();
				}
				else if (update[0] == 'rate_joke')
				{
					tmp = update[1].split ('::');
					var el = document.getElementById ('rating_joke_' + tmp[0] + '_score');
					el.value = tmp[1];

					restoreRate ('joke', tmp[0], 1);
					var dd = document.getElementById('rating_joke_' + tmp[0]);

					dd.removeAttribute('className');	// IE
					dd.onclick = '';	// IE

					dd.removeAttribute('class');
					dd.removeAttribute('onmouseout');

					document.getElementById ('rating_joke_' + tmp[0] + '_voted').innerHTML = tmp[2];
					document.getElementById ('rating_joke_' + tmp[0] + '_vote').style.display = "none";
				}
				else if (update[0] == 'joke_new')
				{
					if (update[1] == 'OK')
					{
						var el = document.getElementById('jokeNew');

						var jokeNewForm = document.getElementById ('jokeForm');
						jokeNewForm.reset();
						jokeNewForm.style.display = 'none';

						jokeTextDoneP = document.createElement("DIV");
						jokeTextDoneP.id = 'jokeNewDone';
						jokeTextDoneTextA = document.createElement("A");
						jokeTextDoneTextA.href = 'javascript:void(0);';
						jokeTextDoneTextA.innerHTML = 'Dodaj novo šalo';
						jokeTextDoneTextA.setAttribute("onClick", "document.getElementById('jokeNewDone').style.display = 'none'; document.getElementById('jokeForm').style.display = 'block';");
						jokeTextDoneP.appendChild(document.createTextNode('Šala je oddana in bo objavljena, ko jo bodo odobrili'));
						jokeTextDoneP.appendChild(document.createElement("BR"));
						jokeTextDoneP.appendChild(jokeTextDoneTextA);

						el.appendChild(jokeTextDoneP);
					}
				}
				else if (update[0] == 'calendar')
				{
					calendarDays = new Array ();
					list = update[1].split ('|');
					try
					{
						tmp = list[5].split ('::');
						for (var n = 0; n < tmp.length; n++)
						{
							calendarDays[tmp[n]] = tmp[n];
						}
					}
					catch (e)
					{
						tmp = null;
					}

					buildCalendar(list[0], list[1], list[2], list[3], list[4]);
				}
				else if (update[0] == 'horoscope')
				{
					var el = document.getElementById ('horoscopeBody');
					tmp = update[1].split ('::');

					DLwrapper = document.createElement ("DL");
					DLwrapper.className = "horoscope";

					DTwrapper = document.createElement("DT");
					DTwrapper.className = "title";
					DTContent = document.createTextNode(tmp[1]);
					DTwrapper.appendChild(DTContent);

					DDwrapper = document.createElement("DD");
					DDwrapper.className = "text";
					DDHoricon = document.createElement("IMG");
					DDHoricon.src = '/' + tmp[3];

					DDContent = document.createTextNode(tmp[2]);
					DDwrapper.appendChild(DDHoricon);
					DDwrapper.appendChild(DDContent);

					DLwrapper.appendChild(DTwrapper);
					DLwrapper.appendChild(DDwrapper);

					if (el.childNodes[0])
						el.childNodes[0].remove;

					if (el.firstChild)
					{
						el.replaceChild (DLwrapper, el.firstChild);
					}
					else
					{
						el.appendChild (DLwrapper);
					}
				}
			}
		}
		else
		{
			alert ('Prišlo je do napake. Poskusite znova.');
		}
	}

	if (activeProgressBar != null)
	{
		activeProgressBar.style.display = 'none';
		activeProgressBar = null;
	}
}

function padDigits (n, totalDigits)
{
	n = n.toString();
	var pd = '';
	if (totalDigits > n.length)
	{
		for (icnt = 0; icnt < (totalDigits-n.length); icnt++)
		{
			pd += '0';
		}
	}

	return pd + n;
}

function getFormData (obj)
{
	getstr = '';

	if (obj.childNodes.length)
	{
		for (var i=0; i < obj.childNodes.length; i++)
		{
/*
			if (!confirm (obj.childNodes[i].tagName + ', value: ' + obj.childNodes[i].innerHTML))
			{
				return false;
			}
*/
			if (obj.childNodes[i].tagName == "INPUT")
			{
				//	TEXT
				if (obj.childNodes[i].type == "text")
				{
					getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				}

				//	HIDDEN
				if (obj.childNodes[i].type == "hidden")
				{
					getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				}

				//	CHECKBOX
				if (obj.childNodes[i].type == "checkbox")
				{
					if (obj.childNodes[i].checked)
					{
						getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
					}
					else
					{
						getstr += obj.childNodes[i].name + "=&";
					}
				}

				//	RADIO
				if (obj.childNodes[i].type == "radio")
				{
					if (obj.childNodes[i].checked)
					{
						getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
					}
				}
			} else if (obj.childNodes[i].tagName == "SELECT")
			{
				var sel = obj.childNodes[i];
				getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
			} else if (obj.childNodes[i].tagName == "TEXTAREA")
			{
				getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
			}
			else if (obj.childNodes[i].tagName != 'undefined')
			{
				getstr+= getFormData (obj.childNodes[i]);
			}
		}
	}

	return getstr;
}

function get (action, obj)
{
	var getstr = "form&" + getFormData (obj);

	sndReq (action, getstr);
}

//	CALENDAR
function getCalendar (type, day, month, year)
{
//	alert ('type: ' + type + ', day: ' + day + ', month: ' + month + ', year: ' + year);
	activeProgressBar = document.getElementById ('calendarProgress');
	activeProgressBar.style.display = 'block';

	//	date init
	var dateObj	= new Date ();
	dataDay	= (day) ? day : dateObj.getDay ();
	dataMonth	= (month) ? month : dateObj.getMonth ();
	dataYear	= (year) ? year : dateObj.getFullYear ();

	sndReq ('calendar', type + '&day=' + dataDay + '&month=' + dataMonth + '&year=' + dataYear);
}

function buildCalendar (type, day, month, year, minDate)
{
	var daysInMonth = new Array(31, ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	date = new Date (year, month - 1, 1);
	dateNow = new Date ();

	dateFirst = (date.getDay () == 0) ? 7 : date.getDay ();
	rows = Math.ceil ((dateFirst + daysInMonth[month - 1] - 1) / 7);

	//	Earliest date
	mdTmp = new Array ();
	try
	{
		mdTmp = minDate.split ('-');
	}
	catch (e)
	{
		mdTmp[0] = dateNow.getFullYear();
		mdTmp[1] = padDigits (parseInt (dateNow.getMonth()) + 1, 2);
		mdTmp[2] = padDigits (parseInt (dateNow.getDate ()), 2);

		minDate = mdTmp[0] + '-' + mdTmp[1] + '-' + mdTmp[2];
	}

	var el = document.getElementById ('calendar_' + type);

	if (el.rows.length)
	{
		cnt = el.rows.length;
		for (i = 1; i <= cnt; i++)
		{
			el.deleteRow(0);
		}
	}

	cntCells = 1;
	cntDays = 1;
	for (i = 1; i <= rows; i++)
	{
		row = el.insertRow(i - 1);
		for (j = 1; j <= 7; j++)
		{
			cell = row.insertCell(j - 1);

			//	mark the weekends
			cell.className = (j > 5) ? 'weekend' : '';

			//	fill the day
			if (cntCells >= dateFirst && cntDays <= daysInMonth[month - 1])
			{
				if (calendarDays[cntDays])
				{
					cellA = document.createElement("A");
					cellA.href = '?date=' + year + '-' + padDigits (month, 2) + '-' + padDigits (cntDays, 2);
					cellA.setAttribute ('title', cntDays + '.' + month + '.' + year);
					cellA.innerHTML = cntDays;
					cell.appendChild (cellA);

					if (day == cntDays)
					{
						cellA.className = 'sel';
					}

					if (cntDays == dateNow.getDate () && month == (dateNow.getMonth () + 1) && year == dateNow.getFullYear ())
					{
						cellA.className = cellA.className + ' today';
					}
				} else {
					cell.innerHTML = cntDays;
				}
				cntDays++;
			} else {
				cell.innerHTML = '&nbsp;';
			}

			cntCells++;
		}
	}

	//	year selector
	yearPrev = (checkValidCalendarDate (minDate, (parseInt (year) - 1) + '-' + padDigits (month, 2) + '-' + padDigits (day, 2), true)) ? parseInt (year) - 1 : year;
	document.getElementById ('calendar' + type + 'YearPrev').onclick = function () {getCalendar (type, day, month, yearPrev); return false;};

	yearNext = (checkValidCalendarDate (minDate, (parseInt (year) + 1) + '-' + padDigits (month, 2) + '-' + padDigits (day, 2), true)) ? parseInt (year) + 1 : year;
	document.getElementById ('calendar' + type + 'YearNext').onclick = function () {getCalendar (type, day, month, yearNext); return false;};

	//	month selector
	if (month == 1) {
		if (checkValidCalendarDate (minDate, (parseInt (year) - 1) + '-12-' + padDigits (day, 2), true))
		{
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, 12, (parseInt (year) - 1)); return false;};
		} else {
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, month, year); return false;};
		}

		monthNext = (checkValidCalendarDate (minDate, year + '-' + padDigits (parseInt (month) + 1, 2) + '-' + padDigits (day, 2), true)) ? parseInt (month) + 1 : month;
		document.getElementById ('calendar' + type + 'MonthNext').onclick = function () {getCalendar (type, day, monthNext, year); return false;};
	} else if (month == 12) {
		if (checkValidCalendarDate (minDate, year + '-11-' + padDigits (day, 2), true))
		{
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, 11, year); return false;};
		} else {
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, month, year); return false;};
		}

		yearNext2 = (checkValidCalendarDate (minDate, (parseInt (year) + 1) + '-01-' + padDigits (day, 2), true)) ? parseInt(year) + 1 : year;
		document.getElementById ('calendar' + type + 'MonthNext').onclick = function () {getCalendar (type, day, 1, yearNext2); return false;};
	} else {
		if (checkValidCalendarDate (minDate, year + '-' + padDigits (parseInt (month) - 1, 2) + '-' + padDigits (day, 2), true))
		{
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, (parseInt(month) - 1), year); return false;};
		} else {
			document.getElementById ('calendar' + type + 'MonthPrev').onclick = function () {getCalendar (type, day, month, year); return false;};
		}

		monthNext2 = (checkValidCalendarDate (minDate, year + '-' + padDigits (parseInt (month) + 1, 2) + '-' + padDigits (day, 2), true)) ? parseInt(month) + 1 : month;
		document.getElementById ('calendar' + type + 'MonthNext').onclick = function () {getCalendar (type, day, monthNext2, year); return false;};
	}

	document.getElementById ('calendar' + type + 'Month').value = month;
	document.getElementById ('calendar' + type + 'Year').value = year;
	document.getElementById ('calendar' + type + 'TitleYear').innerHTML = year;
	document.getElementById ('calendar' + type + 'TitleMonth').innerHTML = monthNames[month - 1];
}

function checkValidCalendarDate (dateLimit, dateCheck, noFuture)
{
	dateLimit = dateLimit.replace (/\-/gi, '');
	dateCheck = dateCheck.replace (/\-/gi, '');

	dateLimit = dateLimit.substring (0,6);
	dateCheck = dateCheck.substring (0,6);

	if (parseInt (dateLimit) <= parseInt (dateCheck))
	{
		if (noFuture)
		{
			dateNowObj = new Date ();
			dateNowStr = dateNowObj.getFullYear() + '' + padDigits (dateNowObj.getMonth() + 1, 2);

			if (parseInt (dateCheck) > parseInt (dateNowStr))
			{
				return false;
			}
		}
	} else {
		return false;
	}

	return true;
}

//	PLUGINS	//

var pollArr = new Array ();

function castVote (vote_id, formObj)
{
	var elements = formObj.elements['pollRadio'];
	var selOption = null;

	for (var cnt = 0; cnt < elements.length; cnt++)
	{
		if (elements[cnt].checked) selOption = elements[cnt].value;
	}

	if (selOption)
	{
		var el = document.getElementById ('pollFrame');
		el.removeChild(document.getElementById('pollForm'));

		loader = document.createElement("DIV");
		loader.id = "pollLoader";
		loaderContent = document.createTextNode("Glasovanje...");
		loader.appendChild(loaderContent);
		el.appendChild(loader);
		sndReq ('poll', selOption);
	}
}

function slideVote (percent)
{
	percent = percent/1 + 2;
	for (var n in pollArr)
	{
		if (pollArr[n] >= percent)
		{
			var el = document.getElementById ('pollBar' + n);
			var el2 = document.getElementById ('pollPer' + n);
			el.style.width = Math.max (1, Math.round (percent/100 * 200)) + 'px';
			el2.innerHTML = '&nbsp;' + percent + '%';
		}
	}

	if (percent < 100) setTimeout ('slideVote("' + percent + '")', 5);
}

function addComment ()
{
	var el = document.getElementById ('reply');
	el.style.display = "block";
}

//	BOOKMARKS
function addBookmark (obj)
{
	get ('bookmark', obj);
}

function removeBookmark (bmId)
{
	if (confirm ('Ste prepričani da želite zbrisati shranjeni članek?'))
	{
		sndReq ('bookmarkDelete', bmId);
	}
}

function editBookmark (bmId)
{
	sndReq ('bookmarkEdit', bmId);
}

function updateBookmark (bmId)
{
	var bmEl = document.getElementById ('bookmarkEdit_' + bmId);
	var bmSel = document.getElementById ('bookmarkEditSelect_' + bmId);
	newSection = bmSel.options[bmSel.selectedIndex].value;

	sndReq ('bookmarkUpdate', newSection + '&bookmarkId=' + bmId);
}

function editBookmarkSection (bmsId)
{
	var bmsEl = document.getElementById ('bookmarkSectionTitle_' + bmsId);

	if (bookmarkNodeOpen != null)
	{
		tmpEl = document.getElementById (bookmarkNodeOpen);
		tmpEl.parentNode.removeChild (tmpEl);
		bookmarkNodeOpen = null;
	}

	if (bookmarkSectionNodeOpen != null)
	{
		eltmp = document.getElementById ('bookmarkSectionInput_' + bookmarkSectionNodeOpen);
		tmp = eltmp.value;
		eltmp.parentNode.removeChild (eltmp);
		document.getElementById ('bookmarkSectionTitle_' + bookmarkSectionNodeOpen).innerHTML = tmp;
		bookmarkSectionNodeOpen = null;
	}

	bmsDiv = document.createElement ('div');
	bmsDiv.id = 'bookmarkSectionEdit_' + bmsId;
	bmsDiv.className = 'editSectionLine';

	bmsDL = document.createElement ("dl");
	bmsDiv.appendChild (bmsDL);

	bmsInput = document.createElement ('input');
	bmsInput.value = bmsEl.innerHTML;
	bmsInput.id = 'bookmarkSectionInput_' + bmsId;

	bmsDD = document.createElement ("dt");
	bmsDD.appendChild (bmsInput);
	bmsDL.appendChild (bmsDD);

	bookmarkSectionNodeOpen = bmsId;

	bmsA = document.createElement ('a');
	bmsImg = document.createElement ('img')
	bmsImg.src = "/dsg/sl/buttons/osvezi.gif";
	bmsA.appendChild (bmsImg);
	bmsA.href = 'javascript:void(0);';
	bmsA.onclick = function () {updateBookmarkSection (bmsId);};

	bmsDD = document.createElement ("DD");
	bmsDD.appendChild (bmsA);
	bmsDL.appendChild (bmsDD);

	bmsEl.innerHTML = '';
//	bmsEl.appendChild(bmsInput);
//	bmsEl.appendChild(bmsA);
	bmsEl.appendChild (bmsDiv);
}

function updateBookmarkSection (bmsId)
{
	var bmsEl = document.getElementById ('bookmarkSectionInput_' + bmsId);

	sndReq ('bookmarkSectionUpdate', bmsEl.value + '&bookmarkSectionId=' + bmsId);
}

function removeBookmarkSection (bmsId)
{
	if (confirm ('Zraven bodo zbrisani vsi shranjeni članki, ki jih imate v tej kategoriji. Sure?'))
	{
		sndReq ('bookmarkSectionDelete', bmsId);
	}
}

function addBookmarkSection ()
{
	var el = document.getElementById ('bookmarkSectionNew');
	if (el.value.length > 0)
	{
		sndReq ('bookmarkSectionNew', el.value);
	}
	else
	{
		alert ('Vnesti morate ime kategorije.');
		el.focus();
	}
}

//	RADAR
function addRadar (radarId)
{
	sndReq ('radar', radarId);
}

function delRadar (radarId)
{
	if (confirm ('Želite zbrisat to besedo?'))
	{
		sndReq ('delRadar', radarId);
	}
}

//	JOKE
function addJoke (obj)
{
	var error = false;

	if (document.getElementById ('jokeNewTitle').value.length == 0)
		error = true;

	if (document.getElementById ('jokeNewSection').value == 0)
		error = true;

	if (document.getElementById ('jokeNewContent').value.length == 0)
		error = true;

	if (error)
	{
		displayMessage ('Izpolnite vsa polja', false);
	}
	else
	{
		get ('joke', obj);
	}
}

//	RATING
function doRate (section, id, rate)
{
	for (i = 1; i <= 5; i++)
	{
		el = document.getElementById ('rating_' + section + '_' + id + '_' + i);
		if (i <= rate)
		{
			el.src = '/dsg/star_on.gif';
		}
		else
		{
			el.src = '/dsg/star_off.gif';
		}
	}
}

function restoreRate (section, id, remove)
{
	score = document.getElementById ('rating_' + section + '_' + id + '_score').value;

	for (i = 1; i <= 5; i++)
	{
		el = document.getElementById ('rating_' + section + '_' + id + '_' + i);
		if (i <= score)
		{
			el.src = '/dsg/star_on.gif';
		}
		else
		{
			el.src = '/dsg/star_off.gif';
		}

		if (remove == 1)
		{
			el.onmouseover = '';	//	IE
			el.onclick = '';	//	IE
			el.removeAttribute('onmouseover');
			el.removeAttribute('onclick');
		}
	}

}

function voteRate (section, id, rate)
{
	sndReq ('rate_' + section, id + '_' + rate);
}
