get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };

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 fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

function setMyCookie(id, bopen) {
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie('item_' + id, bopen, now);
}

	function clearuservalue() {
		document.loginform.user.value = '';
	}

	function cleargoodvalue() {
		document.orderform.count.value = '';
	}

	function toggleorgprop() {
		if (document.cabinet.type.value == 'Юр')
		{
			orgprop.style.display = '';
		} else {
			orgprop.style.display = 'none';
		}
	}

	function toggletree(id) {
		var o_idiv = get_element('i_div_' + id);
		var o_img = get_element('img_' + id);
		if (o_idiv.style.display == 'none') {
			o_idiv.style.display = '';
			if (o_img.name == 'bottom') {
				o_img.src = 'images/icons/minusbottom.gif';
			} else {
				o_img.src = 'images/icons/minus.gif';
			}
			setMyCookie(id, true);
		} else {
			o_idiv.style.display = 'none';
			if (o_img.name == 'bottom') {
				o_img.src = 'images/icons/plusbottom.gif';
			} else {
				o_img.src = 'images/icons/plus.gif';
			}
			setMyCookie(id, false);
		}
	}

	function addToCart(id, count) {
		if (count != null)
		{
			window.open("cart.php?add=" + id + '&count=' + count, "Позиция", "scrollbars=yes, status = no, toolbar = no, menubar = no, height=100, width=500");
		} else {
			window.open("cart.php?add=" + id, "Позиция", "scrollbars=yes, status = no, toolbar = no, menubar = no, height=100, width=500");
		}
		window.location.reload(true);
	}
	
function recalc_good(idCnt, idTotal, Sum) {
	var Cnt = document.getElementById(idCnt).value;
	reg = /^[1-9]*$/;
	if (!Cnt.match(reg)) {
		document.getElementById(idCnt).value = 1;
		Cnt = 1;
	}
	var total = parseInt(Cnt) * parseInt(Sum);
	document.getElementById(idTotal).innerHTML = total + ' руб';
}

function returnCnt(idCnt) {
	return parseInt(document.getElementById(idCnt).value);
}

plusimage = new Image()
plusimage.src = "images/plus.gif"
minusimage = new Image()
minusimage.src = "images/minus.gif"

function showimage(imagename,objectsrc){
	if (document.images) document.images[imagename].src=eval(objectsrc+".src")
}

function opencloseCat(id, imagename) {
	
	var Obj = document.getElementById(id);
	if (Obj.style.display == 'none') {
		Obj.style.display = 'block';
		showimage(imagename, 'minusimage');
	} else {
		Obj.style.display = 'none';
		showimage(imagename, 'plusimage');
	}
}

function showObject(id) 
{
	var Obj = document.getElementById(id);
	Obj.style.display = 'block';
}

function closeObject(id) 
{
	var Obj = document.getElementById(id);
	Obj.style.display = 'none';
}

function showcloseObject(id)
{
	var Object = $(id);
	if (Object.style.display == 'none')
	{
		Object.style.display = 'block'
	}
	else
	{
		Object.style.display = 'none'
	}
}

        var scroll_handler = 0;
        var scroll_start = function(){ if(!scroll_handler) { scroll_handler = window.setInterval(scroll_step,60); } }
        var scroll_stop  = function(){ if(scroll_handler) { window.clearInterval(scroll_handler); scroll_handler = 0; } }
        var scroll_step  = function() {
            if (!scroll_handler) return;
            var avail_height = jQuery("#scroll")[0].scrollHeight;
            var child_height = jQuery("#scroll .scroll_content")[0].scrollHeight;
            var d = jQuery("#scroll .scroll_content");
            var offset = parseInt( d.css("margin-top") );
            if (child_height + offset + 24 > avail_height) { d.css({ marginTop: offset - 5 }); } else scroll_stop();
        }
        jQuery(function(){
            jQuery("#scroll .scroll_content").css({marginTop:0});
            jQuery("#scroll_top").mousedown(function(){ jQuery("#scroll .scroll_content").css({marginTop:0}) });
            jQuery("#scroll_down").mouseup(scroll_stop).mouseout(scroll_stop).mousedown(scroll_start);
        });
