function setStars() {
	if (spans = document.getElementsByTagName('span')) {
		var _voteHandlers = {i: {action: '/vote.action', callee: intUpdateStars}, e: {action: '/collaboration.action', callee: __hUpdateStars}}
		for (var i = 0; i < spans.length; i++) {
			var span  = spans.item(i);
			
			if ('tv-vote' != span.parentNode.className || span.className.match('tv-vote-inactive') || !_voteHandlers[$(span).attr('type')]) continue; 
			
			var _type = $(span).attr('type');
			var actionUrl = _voteHandlers[_type].action
			var successor = _voteHandlers[_type].callee
			for (var j = 1; j < 6; j++) {
				var star = document.createElement('i');
				star.count = j;
				span.appendChild(star);
				star.onmouseover = function(self) {
					this.parentNode.stars = this.parentNode.className;
					this.parentNode.className = 'tv-star' + this.count;
				};
				star.onmouseout = function(self) {
					this.parentNode.className = this.parentNode.stars || this.parentNode.className;
				};
				star.onclick = function(self) {
					this.onmouseover = '';
					this.onmouseout  = '';
					var span         = this.parentNode;
					span.count       = this.count;
					span.innerHTML   = '';
					
					$.ajax({
						type:      'POST',
						dataType : 'json',
						url:       actionUrl,
						data: { id: span.id, rate: span.count, ajax: 'vote', format: 'json' },
						success: function(json) {
							if(json.length){
								successor(json.pop());
							} else {
								span.className = span.stars;
							}
						},
						error: function() {
							span.className = span.stars;
						}
					});
				};
			}
		}
	}
}

function createCookie(name,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = '; expires='+date.toGMTString();
		}
		else var expires = '';
		document.cookie = name+'=1'+expires+'; path=/';
}

function authFocus() {
	if (document.getElementById('authorize')) {
		document.getElementById('authorize').onclick = function() {
			document.getElementById('portals-login').focus();
			document.getElementById('portals-login').className += ' tv-authorize'
			document.getElementById('portals-passwd').className += ' tv-authorize';
			document.getElementById('portals-passwd').value = '';
			return false;
		}
	}
}
