function showMenu(num)
{
	hideMenu();
	changeClass('menu_' + num, 'hover');
}

function hideMenu()
{
	for (i = 1; i < 8; i++) {
		changeClass('menu_' + i, 'normal');
	}
}

function changeClass(id, new_class)
{
    document.getElementById(id).className = new_class;
}

function changeBgColor(obj, new_color)
{
	obj.style.backgroundColor=new_color;
}

function changePic(name, pic)
{
	name.src = pic;
}

function popup(url, name, width, height)
{
	left_pos = (screen.width / 2) - (width / 2);
	top_pos = (screen.height / 2) - (height / 2);
	var popup = window.open(url, name, 'width=' + width + ',height=' + height + ',left=' + left_pos + ',top=' + top_pos +',resizable=1,scrollbars=1');
	popup.focus();
	return false;
}

function cleanField(field, default_value)
{
	if (field.value == default_value) {
		field.value = '';
	}
}

function stars(id_prefix, id, stars, style)
{
	for (i = 1; i <= 5; i++) {
		if (style == "dark") {
			src = (i <= stars) ? '/dsg/star_d.gif' : '/dsg/star_d0.gif';
		} else if (style == "grey") {
			src = (i <= stars) ? '/dsg/star_g.gif' : '/dsg/star_g0.gif';
		} else {
			src = (i <= stars) ? '/dsg/star.gif' : '/dsg/star0.gif';
		}
		document.getElementById(id_prefix + '_' + i).src = src;
		document.getElementById(id_prefix + '_field').value = stars;
	}
}

function vote(id_prefix, type, id, rate, notice)
{
	for (i = 1; i <= 5; i++) {
		document.getElementById(id_prefix + '_' + i).style.cursor = 'default';
		document.getElementById(id_prefix + '_' + i).onmouseover = '';
		document.getElementById(id_prefix + '_' + i).onclick = '';
		document.getElementById(id_prefix + '_' + i).alt = notice;
	}
	document.getElementById(id_prefix).onmouseout= '';
	ajaxCall('?ajax=vote', 'type=' + type + '&id=' + id + '&rate=' + rate);
}

function ajaxCall(url, params)
{
	xmlobj = null;
	try
	{
		xmlobj=new XMLHttpRequest();
	}
	catch(e) {
		try
		{
			xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e)
		{
			xmlobj=null;
			return false;
		}
	}
	xmlobj.open('POST', url, true);
	xmlobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlobj.onreadystatechange = function() {
		if (xmlobj.readyState == 4) {
			xmlobj.status == 200;
			if (xmlobj.responseText) {
				alert(xmlobj.responseText);
			}
		}
	}
	xmlobj.send(params);
}

/* scroller */
var doScroll = false;

function scrollerLeft(elementId)
{
	doScroll = true;
	scroll(elementId, -3);
}

function scrollerRight(elementId)
{
	doScroll = true;
	scroll(elementId, +3);
}

function scrollerStop()
{
	doScroll = false;
}

function scroll(elementId, change)
{
	if (doScroll) {
		element = document.getElementById(elementId);
		margin = element.style.marginLeft;
		if (!margin) {
			margin = 0;
		} else {
			margin = parseInt(margin);
		}
		margin += change;
		if ((margin < 0) && (margin > -444)) {
			margin = margin + 'px';
			element.style.marginLeft = margin;
			window.setTimeout("scroll('" + elementId + "', " + change + ")", 30);
		}
	}
}
