function n2br(str)
{	var seach = '\n';
	var replace = '<br />';
	var s1,s2;
	var strLen=str.length;
	var nLen = seach.length;
	var pos = str.indexOf(seach);
	while (pos != -1)
	{		s1 = str.substr(0, pos);
		s2 = str.substr(pos + nLen, strLen);
		str = s1 + replace + s2;
		pos = str.indexOf(seach);	}
	return str;}
function clear_cart()
{
	cart.clear();
	history.go(0);
}
function addtocart(formName)
{	add_to_cart(formName);
	return false;}
function update_cart(formName)
{	var form = document.getElementById(formName);
	var item = new Item;
	for (i=0;i<fields.length;i++)
	{
		var elem = form.elements[fields[i]];
		if ( typeof(elem) == 'undefined' )
			continue;
		item[fields[i]] = elem.value;	//св-ва товара
	}
	for (i=0; i<r_btns.length; i++)
	{
		var elem = form.elements[r_btns[i]];
		item[r_btns[i]] = elem.value;
	}
	cart.update_product(item,item.quantity);
	cart.serialize();
	//alert (cart.show());
	return false;
}
function refresh()
{	history.go(0);}
function get_color(formName)
{
	//check color
	var form = document.getElementById(formName);
	if ( !GetCheckedRadio(form,'color_id'))
	{		alert('Выберите цвет!');
		return false;	}
	//check size
	var elem = form.elements['size_id'];
	if ( typeof(elem) != 'undefined' )
	{		if (elem.value == -1)
		{			alert('Выберите размер!');
			return false;		}	}
  addtocart(formName);
}
function open_cart(form)
{
	var w = 400;
	var h = 200;
  var winX = 50;
  var winY = 50;
  if (parseInt(navigator.appVersion) >= 4) {
    winX = (screen.availWidth - w)*.5;
    winY = (screen.availHeight - h)*.25;
  }
  popupWin = window.open('add_cart.php3?fname='+form, 'add_cart', 'scrollbars=no,resizable=no,status=no,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
}

function display_form(form_id)
{
	hide_forms();
	var dest = document.getElementById(form_id);
	if ( "block" == dest.style.display )
	{
		dest.style.display = "none";
	}
	else
	{
		dest.style.display = "block";
		dest.style.left = (getClientCenterX() - dest.clientWidth/2)+'px';
		dest.style.top = (getClientCenterY() - dest.clientHeight/2)+'px';
	}
}

function hide(form_id)
{	var dest = document.getElementById(form_id);
	dest.style.display = "none";}

function hide_forms()
{	var reg =/ss\d+/;
	var i=0;
	for (i = 0; i < document.forms.length; i++)
	{		if ( reg.test(document.forms[i].id) )
		{			hide(document.forms[i].id)		}	}}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}
function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}
function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}
function get_thumb(id,name)
{
	var elem = document.getElementById(id);
	elem.src=name;
	elem.style.borderWidth="1px";
}
function rem_thumb(id)
{
	var elem = document.getElementById(id);
	elem.style.borderWidth="0px";
	elem.src='/image/empty.gif';
}

function winfoto(url, name, w, h) {
  var winX = 50;
  var winY = 50;
  if (parseInt(navigator.appVersion) >= 4) {
    winX = (screen.availWidth - w)*.5;
    winY = (screen.availHeight - h)*.25;
  }
  popupWin = window.open(url, name, 'scrollbars=no,resizable=no,status=yes,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
}
