function detail_tovar(id,hidden,e)
{

if (hidden=="Y")
  jsAjaxUtil.InsertDataToNode('/catalog/detail.php?ID='+id+'&hidden=Y', 'popup-window', false);
else
  jsAjaxUtil.InsertDataToNode('/catalog/detail.php?ID='+id, 'popup-window', false);

  var div=document.getElementById("popup-window");

	var posx = 0;
	var posy = 0;

	posy=parseInt(getClientHeight()/2)+getBodyScrollTop();
	posx=parseInt(getClientWidth()/2)+getBodyScrollLeft();



if (div)
{
div.style["top"]=(posy-300)+'px';
div.style["left"]=(posx-360)+'px';
}
//  window.open("/catalog/detail.php?ID="+id,id,"width=742,height=550,location=0,status=0,scrollbars=0");
}


function getClientHeight()
{
  return ((document.compatMode=='CSS1Compat')?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 getClientWidth()
{
  return document.compatMode=='CSS1Compat'?document.documentElement.clientWidth:document.body.clientWidth;
}

function detail_close()
{
  var div=document.getElementById("popup-window");
  div.innerHTML="";
}

function location1()
{
str="";
if (document.forms['complect']['ELCOMPLECT'])
str+=document.forms['complect']['ELCOMPLECT'].value;
if (document.forms['complect']['region'])
str+='&region='+document.forms['complect']['region'].value;
if (document.forms['complect']['OUT_CITY'])
str+='&city='+document.forms['complect']['OUT_CITY'].value;

if (document.forms['complect']['OUT_COUNTRY'])
str+='&country='+document.forms['complect']['OUT_COUNTRY'].value;

str+='&rand='+Math.random();

return str;
}
function region_change(in1,out2,id)
{
  var d=document;


  	var div2=d.getElementById("region_in_city");
	var div3=d.getElementById("region_out");

if (div3)
{
  		if (id==out2)
		{

			div2.style.display="none";
			div3.style.display="";
		}
			else
		{
			div2.style.display="";
			div3.style.display="none";
		}

}

}

function elements(id,operation)
{
  var EL=document.forms['complect']['ELCOMPLECT'];

 var test=new Array();
 id=id+'';
 test=id.split('_');

 if (test[1]>0)
 {
  var l=test[0].length;
 }


if (EL)
{
  var str=EL.value;
  var els=new Array();
  var newels=new Array();

  els=str.split(',');

 if (id)
 {
  var j=0;
  if (operation=='del')
	{
 		for ( var i in els)
		{
			if (els[i]!=id)
			{	newels[j]=els[i]; j++;}
		}
	
		EL.value=newels.join(',');

	}


  if (operation=='add')
	{

if (l>0)
{
	var j=0;

	for ( var i in els)
		{
			if (els[i].substr(0,l)!=test[0])
			{	newels[j]=els[i]; j++;}
		}

		str=newels.join(',');

}

		str+=','+id;
		EL.value=str;
	
	}
 }

}



}

function waitings()
{
  var d=document;
  var div=d.getElementById("dprice");
  if (div)
	{
		div.innerHTML="идет расчет...";
	}
}


function clear_price()
{
  var d=document;
  var div=d.getElementById("dprice");
  if (div)
	{
		div.innerHTML="неизвестна";
	}

copy_table_complect();
}

function copy_table_complect()
{
  var d=document;
  var div=d.getElementById("table_complect");
  var div2=d.getElementById("table_complect_copy");
  if (div2)
	{
		div2.innerHTML=div.innerHTML;
	}
}

function group_show(group)
{
  var d=document;
  var div=d.getElementById("group"+group);
  if (div)
	{
		div.style["display"]="";
	}

}
function group_select(group,id)
{
  var d=document;
  var div=d.getElementById("group"+group);
 // if (div) {div.style["display"]="none";}


  var pic=d.getElementById("tovar_"+id);
  var td=d.getElementById("group_sel_"+group);

if ((pic)&&(td)) {
  td.innerHTML=pic.innerHTML;

	clear_price();

elements('s'+group+'_'+id,"add");

}


}



function summ()
{
 var d=document;
 var add_kor=0;

    var base=d.forms["complect"]["BASE_PRICE"];
	var addprice=d.forms["complect"]["ADD_PRICE"];
	var korprice=d.forms["complect"]["KOROBKA_PRICE"];

	clear_price();

  var kor=d.getElementById("complect_korobka");
 if (kor)
 {
  if (kor.style["display"]=="")
  add_kor=korprice.value;
 }


return parseInt(base.value)+parseInt(addprice.value)+parseInt(add_kor);
}

function spring(price)
{
  var d=document;
  var addprice=d.forms["complect"]["ADD_PRICE"];
  var spring=d.forms["complect"]["letter_spring"];
  var bprice1=d.getElementById("price1");
  var bprice2=d.getElementById("price2");

if (spring.checked)
{
addprice.value=parseInt(addprice.value)+parseInt(price);
}
else {
addprice.value=parseInt(addprice.value)-parseInt(price);
}

bprice1.innerHTML=summ();
bprice2.innerHTML=bprice1.innerHTML;
}


function del_complect(id,price,hash)
{
  var d=document;
  var td=d.getElementById("dop_tovar_"+hash);
  var addprice=d.forms["complect"]["ADD_PRICE"];
  var bprice1=d.getElementById("price1");
  var bprice2=d.getElementById("price2");

  if (td)
	{
		td.innerHTML="";
		td.style["display"]="none";

		addprice.value=parseInt(addprice.value)-parseInt(price);
	}
  var kor=document.getElementById("complect_korobka");

if (kor)
{
	if (parseInt(addprice.value)>0)
	kor.style["display"]="";
	else kor.style["display"]="none";
}
bprice1.innerHTML=summ();
bprice2.innerHTML=bprice1.innerHTML;

elements(id,'del');

}

function add_complect(id,name,price,who)
{
  var d=document;
  var pic=d.getElementById("tovar_"+id);
  hash=parseInt(Math.random()*100000);

  var tr=d.getElementById("elements");
  var bprice1=d.getElementById("price1");
  var bprice2=d.getElementById("price2");

if (pic) {
  var newCell=tr.insertCell(-1);
  newCell.id="dop_tovar_"+hash;
  newCell.innerHTML=name+'<BR>'+pic.innerHTML+"<input type='hidden' name='dop_tovar[]' value='"+id+"'><br>";

if (0&&who=="obr_short")
{ 
	newCell.innerHTML+='<input type="text" size=15 name="obr['+id+']" value="кому?"><br>';
}

 newCell.innerHTML+="Цена: "+price+" руб.<br><a href='javascript:void(0);' onclick='del_complect("+id+","+price+",\""+hash+"\")'>удалить</a>";


	var addprice=d.forms["complect"]["ADD_PRICE"];
	addprice.value=parseInt(addprice.value)+parseInt(price);

  var kor=document.getElementById("complect_korobka");

if (kor)
{
	if (parseInt(addprice.value)>0)
	kor.style["display"]="";
	else kor.style["display"]="none";
}


bprice1.innerHTML=summ();
bprice2.innerHTML=bprice1.innerHTML;

elements(id,'add');
}

}