<!--

function ImgCheckbox(imgId, inputId, imgOn, imgOff) {
    this.imgOn   = imgOn
    this.imgOff  = imgOff
    this.image   = document.getElementById(imgId)
    this.input   = document.getElementById(inputId)

    this.preload_imgOn      = new Image()
    this.preload_imgOn.src  = imgOn
    this.preload_imgOff     = new Image()
    this.preload_imgOff.src = imgOff

    this.input.style.display = "none"
    this.image.style.display = "inline"
    
    this.setState(this.input.checked)
}

ImgCheckbox.prototype.setState = function(state) {
    this.input.checked     = state
    this.image.src   = state ? this.imgOn : this.imgOff
}

ImgCheckbox.prototype.flip = function() {
    this.setState(!this.input.checked)
}

function showBlock(id) {

   var elm = document.getElementById(id);
   if (elm) {
     elm.style.display = 'inline';
   }
}

function hideBlock(id) {
   var elm = document.getElementById(id);
   if (elm) {
     elm.style.display = 'none';
   }
}

function changeRating(struct_id, rating, alias, section_id) {
	if (!eval('flag' + struct_id)) {
		if (getCookie('np_user_id') && !getCookie('item' + struct_id)) {

			var elm = document.getElementById('item' + struct_id);
			if (elm) {
				elm.innerHTML = parseInt(elm.innerHTML) + rating;
			}
			
			var elm = document.getElementById('item_sum' + struct_id);
			if (elm) {
				elm.innerHTML = parseInt(elm.innerHTML) + rating;
			}
			
			if (rating > 0) sign = 'plus';
			else sign = 'minus';
			    
			var elm = document.getElementById('item_' + sign + struct_id);
			if (elm) {
				elm.innerHTML = parseInt(elm.innerHTML) + 1;
			}
			
			document.getElementById('aup' + struct_id).style.cursor="default";
			document.getElementById('adown' + struct_id).style.cursor="default";
			
			eval('flag' + struct_id + ' = 1');
			document.images['up' + struct_id].src = '/images/up2.gif';
			document.images['down' + struct_id].src = '/images/down2.gif';
			
			//var now = new Date();
			//now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
			//setCookie('item' + struct_id, 1, now, '/');
			
			top.iframe.location.href = '/misc/change_rating.php?struct_id=' + struct_id + '&rating=' + rating + '&alias=' + alias + '&section_id=' + section_id;
		}
	}
}

function checkRating(struct_id) {
	if (!getCookie('np_user_id') || getCookie('item' + struct_id)) {

		var elm = document.getElementById('aup' + struct_id);
		if (elm) {
			elm.style.cursor = "default";
		}

		var elm = document.getElementById('adown' + struct_id);
		if (elm) {
			elm.style.cursor = "default";
		}
		
		eval('flag' + struct_id + ' = 1');
		document.images['up' + struct_id].src = '/images/up2.gif';
		document.images['down' + struct_id].src = '/images/down2.gif';
	}
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
     ((expires) ? "; expires=" + expires.toGMTString() : "") +
     ((path) ? "; path=" + path : "") +
     ((domain) ? "; domain=" + domain : "") +
     ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	    begin = dc.indexOf(prefix);
	    if (begin != 0) return null;
	} else
	     begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	    end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
//-->