pagebasket=false;
drgid=false;
fdi=false;
chnt=false;
fdtimer = false;
if (window.navigator.userAgent.indexOf ("Gecko") >= 0) {ie = false;} else {ie=true;}
inbask= new Array();
insum= new Array();
ginbask = new Array();
var picid = false;
var showfull=false;
var picparams = new Array();

String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
}

function sendorder(){
		out='';
		for(i=0; i<mands.length;i++){
		if(document.getElementById(mands[i][0]).value=='') {
			out+='не заполнено поле "' + mands[i][1] + '"\n';
	}
}
		if(out!='') {
			alert('Ошибка !\n' + out);
			return false;
			}
		ok = confirm("Вы уверены, что все введённые Вами данные верны ?");
		if(ok) document.form.submit();
	else return false;
	
}

function hi(obj,now){
	if(!obj) obj = document.getElementById('ltd_' + document.getElementById('curgood').value);
	if(!fdi || now) {
show(obj,0);
hidep();
}
else {
	ids = obj.id.split('_'); 
	id=ids[1];
	if(id==document.getElementById('curgood').value) fdtimer = setTimeout("closediv();", 3000);
	}
}

function sh(obj){
if(!obj) {
		 clearTimeout(fdtimer); 
}

else if(!fdi) {
 show(obj,1);
 iid = obj.id.replace('ltd_','');
 fillp(obj, mparams[iid]);  
 clearTimeout(fdtimer);

}

}

function ct(v){

		if(v==1){ hidtr('city_tr'); hidtr('dist_tr');chnum(11,0); document.getElementById('city').value = 'Москва';}
		if(v==2){ hidtr('city_tr'); shotr('dist_tr');	document.getElementById('city').value = 'Москва';}
		if(v==3){shotr('city_tr'); shotr('dist_tr'); }
}

function adr(val){

		if(val=='1' || !val) {
					document.getElementById('adrtable').style.display='none';
					chnum(10,0);
					chnum(11,0);
		}

		if(val=='2') {
					document.getElementById('adrtable').style.display='inline';

										chnum(10,1);
										chnum(11,0);
		}

}

function showbasket(){
		closebasket();
		var b = new loadbasket('/basket.php?x=x');
		b.doGet();
}

function chnum2(id, num){
			if(isNaN(num)) num=0;
				clearTimeout(chnt);
    		chnt = setTimeout('chnum(' + id + ',' + num + ')', 500);
}

function chnum(id, num){

			if(isNaN(num)) num=0;
    		var b = new loadbasket('/basket.php?change=' + id + '&num=' + num);
				b.doGet();
}
function tobasket(id, num,toba){
		dv = document.getElementById('bskpic_' + id);
		var b = new loadbasket('/basket.php?add=' + id + '&num=' + num);
		b.doGet();
		nn = document.getElementById("num_" + id);
		if(!nn) nn = document.getElementById('inputl');
		if(nn) nn.value=1;
		
	}


function frombasket(id){
		var b = new loadbasket('/basket.php?del=' + id);
		b.doGet();
}


function loadbasket(url, callback){
url=url + '&rand=' + Math.random();


var callback = function (xml){

if(xml.getElementsByTagName("order")[0].childNodes[0]) {
	oid = xml.getElementsByTagName("order")[0].childNodes[0].nodeValue;
	price = xml.getElementsByTagName("price")[0].childNodes[0].nodeValue;
	cnt = xml.getElementsByTagName("count")[0].childNodes[0].nodeValue;
	
	if(xml.getElementsByTagName("addedid")[0].childNodes[0]) {
		var addedid = xml.getElementsByTagName("addedid")[0].childNodes[0].nodeValue; 
		} 
		else {var addedid='';}


	if(xml.getElementsByTagName("addednum")[0].childNodes[0]) {
		var addednum = xml.getElementsByTagName("addednum")[0].childNodes[0].nodeValue; } 
		else {			var addednum='';		}
		;
if(xml.getElementsByTagName("addedsum")[0].childNodes[0]) {
		var addedsum = xml.getElementsByTagName("addedsum")[0].childNodes[0].nodeValue; } 
		else {			var addedsum='';		}
		;

	

	if(cnt>0){
	bsk= document.getElementById('basket_big').src='/images/basketbigf.jpg';
	document.getElementById('basket_empty').style.display='none';
	document.getElementById('basket_full').style.display='block';
	document.getElementById('bsk_fly').style.display='block';

	document.getElementById('bsk_count').innerHTML=cnt + ' ' + tovars(cnt);
	document.getElementById('bsk_price').innerHTML=numformat(price);
	document.getElementById('bsk_fly_count').innerHTML=cnt + ' ' + tovars(cnt);
	document.getElementById('bsk_fly_price').innerHTML=numformat(price);

	if(document.getElementById('itogo')) 	document.getElementById('itogo').innerHTML=numformat(price);
	if(document.getElementById('itogocnt')) 	document.getElementById('itogocnt').innerHTML=cnt;

	allc = document.getElementById('all_count');
	allp = document.getElementById('all_price');
	if(allc) allc.innerHTML=cnt;
	if(allp) allp.innerHTML=numformat(price);
	}
	goods = xml.getElementsByTagName("good");
	inmkad = outmkad = 0;

for(i=0; i<goods.length ; i++) {
         g_id = goods[i].getAttribute("id");         
         gcnt = goods[i].getAttribute("count");
		 sum = goods[i].getAttribute("sum");  
		 coun = goods[i].getAttribute("coun"); 
		 ginbask[i]=g_id;
	
			if(addedid==g_id) {
					shcook = getCookie('hidewin');

					if(shcook!=1){
				
						addiv=document.getElementById('bigadded');
						addivn=document.getElementById('addednum2');
						addivs=document.getElementById('addedsum2');
						addivt=document.getElementById('addedtov2');

						if(addednum<cnt){
						
						alldiv=document.getElementById('allbask');
						alldivn=document.getElementById('allnum2');
						alldivs=document.getElementById('allsum2');
						alldivt=document.getElementById('alltov2');
						alldiv.style.display='block';
						alldivn.innerHTML=cnt;
						alldivt.innerHTML=tovars(cnt);
						alldivs.innerHTML=numformat(price);
					}
						}
			else {
						addiv=document.getElementById('addeddiv');
						addivn=document.getElementById('addednum');
						addivs=document.getElementById('addedsum');
						addivt=document.getElementById('addedtov');
					}

					if(addiv && !pagebasket) {
					addivs.innerHTML=numformat(addedsum);
					addivn.innerHTML=addednum;
					addivt.innerHTML=tovars(addednum);
					addiv.style.display='block';
						}
						nm=document.getElementById('num_' + g_id);
						if(!nm) nm = document.getElementById('inputl');
						if(!nm) nm = document.getElementById('tobasa_' + g_id);
						
						
if(shcook==1) {						
						addiv.style.top=getPos(nm,'Top') + 'px';
						addiv.style.left=(getPos(nm, 'Left')-220) + 'px';
						setTimeout("document.getElementById('addeddiv').style.display='none';", 3000);
}
else{
		
	ttx = parseInt(document.body.clientWidth/2-600/2);
	tty = parseInt(ssize('h')/2-330/2) + gscroll();

		addiv.style.top=tty + 'px';
		addiv.style.left=ttx + 'px';
	
}

						}
	


	
	
		 if(coun>0) gid = g_id + '_' + coun; 
			else gid=g_id;

					inbask[gid] = gcnt;
					insum[gid] = sum;

				 if(gid == 10) { inmkad = sum;}
				 if(gid == 11) { outmkad = sum;}

			   	gdiv = document.getElementById('bskpic_' + gid);            
 			   	gdiv_small = document.getElementById('bskpic_small_' + gid);
				lukdiv = document.getElementById('ltd_' + g_id);

			if(lukdiv) lukdiv.style.fontWeight='bold';
			if(gdiv) gdiv.style.background='url(/images/basket_full.png)';
			if(gdiv_small) gdiv_small.style.background='url(/images/basket_small_full.png)';


			   ginp = document.getElementById('bkinp_' + gid);
							 if(ginp) {
							 ginp.value=gcnt;
							 }

			   gsum = document.getElementById('sum_' + gid);
							 if(gsum) {
							 if(Math.round(sum)==sum) sum=Math.round(sum);
							 gsum.innerHTML=numformat(sum); 
							 }

				arrdiv = document.getElementById('bsk_arrows_' + gid);
				if(arrdiv) arrdiv.style.display='block';
		}
				ddiv = document.getElementById('price_dost');

				if(ddiv) {
				sdiv = document.getElementById('pricesum');
				fdiv = document.getElementById('price_full');
				pr = parseInt(sdiv.innerHTML);

				
				dprice = (parseInt(inmkad) + parseInt(outmkad));

				ddiv.innerHTML = dprice;
				
    		pf = numformat(price);

				fdiv.innerHTML = pf;
};
				
}
}

   var req = init();
   req.onreadystatechange = processRequest;

 function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
 }

 function processRequest() {
      if (req.readyState == 4) {
        if (req.status == 200) {
          if (callback) callback(req.responseXML);

        }
      }
    }


    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
 }

 
 
 function hidtr(trid){
if(document.getElementById(trid)) {

if(ie) {
	document.getElementById(trid).style.display = 'none';
	}
	else {
	document.getElementById(trid).style.visibility = 'collapse';
	}
}

}

function shotr(trid){
if(document.getElementById(trid)) {
if (ie) {
	document.getElementById(trid).style.display = 'inline';
	}
	else  {
	document.getElementById(trid).style.visibility = 'visible';
			  }
}
}



function show(cell, cla){
			rw=cell.parentNode.parentNode;
			tb = rw.parentNode;
			col= cell.parentNode.cellIndex;
			row = rw.rowIndex;
			rows=tb.rows.length;
			cols=rw.cells.length;

			ce1 = tb.rows[2].cells[col-1].childNodes[0];
			ce2 = tb.rows[row].cells[0].childNodes[0];

		if(cla=='1') {
						if(cell.className=='sc') cell.style.backgroundColor='#567B94';
						if(cell.className=='sc23557') cell.style.backgroundColor='#006699';
						if(cell.className=='sc23502') cell.style.backgroundColor='#009966';
						cell.style.color='#fff';
						ce1.style.background=ce2.style.background='#fff';
						ce1.style.color=ce2.style.color='#567B94';
						
			
				}

	
//					  cell.className = cell.className + 'cur';  
//					  ce1.className = ce2.className = 'sizeheadc_sel';  

		

		if(cla=='0') {
						if(cell.className=='sc') cell.style.backgroundColor='#fff';
						if(cell.className=='sc23557') cell.style.backgroundColor='#efefff';
						if(cell.className=='sc23502') cell.style.backgroundColor='#00FF99';

						cell.style.color='#000';
						ce1.style.background=ce2.style.background='#567B94';
						ce1.style.color=ce2.style.color='#fff';

						
						// cell.className = cell.className.replace('cur', '')
							//ce1.className = ce2.className = 'sizeheadc';  
		}

	
}



function hidep(){

			pardiv=document.getElementById('paramdiv');
			pardiv.style.display='none';

}
function fillp(obj, para){
	tblnode = obj.parentNode.parentNode.parentNode.parentNode;
		tw = getSize(tblnode, 'Width');
		if(tw<700) tw=700;
		tx = getPos(tblnode, 'Left');

		th = getSize(tblnode, 'Height');
		ty = getPos(tblnode, 'Top');
		document.getElementById('lukprice').innerHTML=obj.innerHTML;
		x=obj.id.split('_');
		id = x[1];
		
		document.getElementById('curgood').value = id;
		bstd = document.getElementById('bastd');
//		itd = document.getElementById('inptd');
//		sumd = document.getElementById('sumdiv');
	if(curcou[id]) {
		pa = curcou[id];
		idpa = id + '_' + pa;
}	 else idpa=id;


		bstd.childNodes[0].id='bskpic_' + idpa;
		if(inbask[idpa]>0) {inbas=inbask[idpa];} else inbas=0;
		if(insum[idpa]>0) {insu=insum[idpa];} else insu=0;
			x=getPos(obj, "Left");
			y=getPos(obj, "Top");
			tbl=document.getElementById('params');
			pardiv=document.getElementById('paramdiv');
			pardiv.style.display='block';


	  if(y+100+getSize(tbl, 'Height') > 	th+ty) 	pardiv.style.top=(y-80) +  'px';
		else pardiv.style.top=(y+20) +  'px';
	
//			window.status = x + ' ' + tx;
	  if(x+250 > 	tx+tw) 	pardiv.style.left=(x-393) +  'px';
		else pardiv.style.left=(x+40) +  'px';

			for(t=0; t<tbl.rows.length; t++) {
       			        hidtr(tbl.rows[t].id);               
						tbl.rows[t].cells[1].childNodes[0].innerHTML='';
			}

			paras = para.split(';');

			for(i=0; i<paras.length; i++) {
					par = paras[i].split('=');
					sp = document.getElementById('param_' + par[0]);
					if(sp) {
					sp.innerHTML+='<b>' + par[1] + '</b>'}
					shotr('tr_' + par[0]);
	}


	
		if(inbas>0) {

			bstd.childNodes[0].style.background='url(/images/basket_full.png)';}
		else {
				   bstd.childNodes[0].style.background='url(/images/basket.png)';}

}

function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}


function fixdiv(obj,para,id){
	document.getElementById('basketdiv').style.display='block';
	document.getElementById('basketdiv').onclick=function(){
	tobasket(id);
	}
}


function clearbasket(){

			ok = confirm('Вы уверены, что хотите очистить корзину ?');
			if(ok) {
					var b = new loadbasket('/basket.php?action=clear');
						b.doGet();
						
						setTimeout("window.location='/basket/1'",1000);
			}
}


function clearchecked(){
			ids = '';
			ok = confirm('Вы уверены, что хотите удалить отмеченные товары из корзины ?');
			if(ok) {

							for(i=0; i<ginbask.length;i++){
										idd = ginbask[i];
									if(document.getElementById('hcb_' + idd) && document.getElementById('hcb_' + idd).checked) ids+='.' + idd;
									
							}
							
					var b = new loadbasket('/basket.php?clear=' + ids);
						b.doGet();


						window.location='/basket/1';
			}
}


function tl(td){
		x=td.id.split('_');
		id = x[1];

if(!fdi){


		fdi=true;
		document.getElementById('krdiv').style.display='block';
		if(curcou[id]) {
		pa = curcou[id];
		idpa = id + '_' + pa;

}	 else idpa=id;
//		tobasket(idpa, 1);
		}

else {
	curg=document.getElementById('curgood').value;
	fdi=false;
	if(curg!=id){
	hi();
	sh(td);
	}
else {
	tl(td);

			}
		}
	}

function loadscroll(y){
//				window.scrollTo(0,y);
}

function savescroll(){
	    			setCookie('scroll', gscroll());
}
function gscroll(){
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

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



function deleteCookie ( cookie_name, path )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString() +         ((path) ? "; path=" + path : "") ;
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}




function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}
function getSize(el,sProp) {
	var iPos = 0;
		iPos+=el["client" + sProp]
	return iPos
}

function resize(objid,tx,ty,tw,th,secs,hide){
	
		obj=document.getElementById(objid);
		if(secs>0) {
		cx = getPos(obj, 'Left');
		cy = getPos(obj, 'Top');
		cw = getSize(obj, 'Width');
		ch = getSize(obj, 'Height');
		dx=(tx-cx)/(secs/50);
		dy=(ty-cy)/(secs/50);
		dw=(tw-cw)/(secs/50);
		dh=(th-ch)/(secs/50);
		nx = cx+dx;
		ny = cy+dy;
		nw = cw+dw;
		nh = ch+dh;

	stimer = setTimeout('resize("' + objid + '", ' + tx + ',' + ty + ','+ tw + ',' + th + ','+ (secs - 50) + ',' + hide + ')',50);
			obj.style.left=nx +'px';
			obj.style.top=ny +'px';
			obj.style.width=nw +'px';
			obj.style.height=nh +'px';


			
		} else {

		if(hide==1) {obj.style.display='none';
			}
		if(hide==2) {
			document.getElementById('smparr').style.display='block';
			slowshow('smparr',0,1,300);
			disppic(0);
if(sptd) {
			
		
	cont = document.getElementById("smpcont");
	sc = cont.scrollLeft;
	tdsc = 	sptd.offsetLeft;
	slowscroll("smpcont",sc,parseInt(tdsc-350),500);
}
			}
		if(hide==3) {
						disppic(0);
	cont = document.getElementById("smpcont");
	sc = cont.scrollLeft;

	if(sptd) {
		tdsc = 	sptd.offsetLeft;
	slowscroll("smpcont",sc,parseInt(tdsc-350),500);
		}
			
			}

			}
}


function slowshow(objid,b,e,secs,aft){

	obj=document.getElementById(objid);
		d=(e-b)/(secs/50);


		if(secs>0) {
			no = b+d;
				if(ie) {
					var fff = "alpha(opacity=" + parseInt(no*100) + ")";
					obj.style.filter = fff; 
				}
					else obj.style.opacity = no;
		stimer = setTimeout('slowshow("' + objid + '", ' + no + ',' + e + ','+ (secs - 50) + ')',50);
			
		} 
		if(aft==1) {obj.style.display="none";}	
		}



function hidepic(){
				showfull=false;
				sd=document.getElementById('sdiv_' + curpic);
			    tx=getPos(sd, 'Left'); ty=getPos(sd, 'Top');
				tw=getSize(sd, 'Width'); th=getSize(sd, 'Height');
				
				slowshow('origpic',1,0,200,1);
				slowshow('smparr',1,0,200,1);
				setTimeout("resize('pdiv', " + tx + "," +  ty + "," + tw + "," +  th + ", 250,1)", 100);
}



function chpic2(fname,wi,he,id,des,nn,pid){
	if(fname=='nofoto.jpg') {
		return false;
	}

				picid = document.getElementById("origpic");
				picparams = new Array(fname,wi,he,id,des,nn,pid);
				otdid = 'd2pic_current_' + curpic2;
				otd = document.getElementById(otdid);
				pd = document.getElementById("pdiv");
				if(pd.style.display!="block") nn=true;
	if(otd) {otd.style.backgroundColor="#ffffff"};
		
				picid = document.getElementById("origpic");
				if(des) document.getElementById("bigpicdesc").innerHTML=des;
	if(!nn){
				to=200;
				ht = 3;
				slowshow("origpic", 1,0,500);
				setTimeout('document.getElementById("origpic").style.display="none"', to);
} else {
	pcs = document.getElementById("picsdiv2_" + id);
	if(pcs) document.getElementById("smallpics2").innerHTML=pcs.innerHTML.replaceAll('d2pic_' + id, 'd2pic_current');

	if(id==1) {
		sd=document.getElementById('sdiv_' + pid);
		curpic = pid;
	}
	else { 
		sd=document.getElementById('sdiv_' + id);
		curpic = id;	
	}

	tx=getPos(sd, 'Left'); ty=getPos(sd, 'Top');
	tw=getSize(sd, 'Width'); th=getSize(sd, 'Height');
	pd.style.width=tw + 'px';
	pd.style.height=th + 'px';
	pd.style.left=tx + 'px';
	pd.style.top=ty + 'px';
	pd.style.display='block';
	
	to=0;
	ht=2;
polosa=170;
	if(!pcs){
		ht=3;
		polosa=50;
		document.getElementById("smparr").style.display="none";
}
else polosa=170;

	}
curpic2=pid;
ni = new Image();
ni.onload= function(){ 
		picloaded(); 
	}
ni.src='/pictures/original/' + fname;
plo=false;

		pwi=parseInt(wi) + 20;
		pw=parseInt(wi);
		ph=parseInt(he);
		phe = parseInt(he) + polosa;

if(phe>ssize('h') && showfull!=true) {
	ratio = ph/pw;
	ph=ssize('h') - 30 - polosa;
	pw=parseInt(ph/ratio);

	}

if(phe>ssize('h') && !showfull) {
	document.getElementById('big_lupa_img').src='/images/big_lupa.png';
	document.getElementById('big_lupa').style.display='block';
}

else if(phe>ssize('h') && showfull) {
	document.getElementById('big_lupa_img').src='/images/big_antilupa.png';
	document.getElementById('big_lupa').style.display='block';
}
else if(phe<=ssize('h')) 	document.getElementById('big_lupa').style.display='none';

	setTimeout('document.getElementById("origpic").style.width='  + pw + ' + "px"',to);
	setTimeout('document.getElementById("origpic").style.height='  + ph + ' + "px"',to);

	phe=ph+polosa;
	pwi=pw+20;
	pwm = pwi;
	if(pwm<900) pwm=900;
	tx = parseInt(document.body.clientWidth/2-pwm/2);
	ty = parseInt(ssize('h')/2-phe/2) + gscroll();

	if(pcs){
		
	
	tdid = 'd2pic_current_' + pid;

	sptd = document.getElementById(tdid);
	sptd.style.backgroundColor='#eee';
	

		
	if(sptd.nextSibling && sptd.nextSibling.onclick) {
		document.getElementById("big_right").onclick = sptd.nextSibling.onclick; 
		slowshow("big_right",1,1,50);
		document.getElementById("big_right").style.cursor='pointer';
	} else 	{
		
		slowshow("big_right",0.3,0.3,50);
		document.getElementById("big_right").style.cursor='default';
		document.getElementById("big_right").onclick=null;
		}


	if(sptd.previousSibling && sptd.previousSibling.onclick) {
		document.getElementById("big_left").onclick = sptd.previousSibling.onclick;
				slowshow("big_left",1,1,50);
		document.getElementById("big_left").style.cursor='pointer';
		
	} else 		{
		slowshow("big_left",0.3,0.3,50);
		document.getElementById("big_left").style.cursor='default';
		document.getElementById("big_left").onclick=null;
	}

	
	
	}
	if(ty<10) ty=10;
		setTimeout("resize('pdiv', " + tx + "," + ty + ","  + pwm + ","  + phe + ", 300," + ht + ")", to);
}











function chpic(fname,id,des,pid){
				picid = document.getElementById("bigpic_" + id);
				slowshow("bigpic_" + id, 1,0,200);
				setTimeout("picid.src='/pictures/big/" + fname + "'",200);
				setTimeout("slowshow('bigpic_" + id + "', 0,1,200)",500);
				document.getElementById("lupa_" + id).onclick = document.getElementById("d2pic_" + id + "_" + pid).onclick;
				document.getElementById('descdiv_' + id ).innerHTML=des;
}

function ssize(t) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

	if(t=='w') {
			return myWidth;
			}
			else {
			return myHeight;
			}
}

function lupa(id){
lup = document.getElementById('lupadiv_' + id);
if(lup) {
sd=document.getElementById('sdiv_' + id);
lup.style.left=getPos(sd, 'Left') + 'px';
lup.style.top=getPos(sd, 'Top') + 'px';
if(origpic[id]=='nofoto.jpg' || (gwi<=310 && ghe<=310)) {lup.style.display='none';} else {lup.style.display='block';}
}
}

function drag(id,type){
			drgid=id;
			obj=document.getElementById('slideract_' + drgid);
			drgtype=type;
			begx=mousex;
			drgmal=obj.style.marginLeft;
			drgmar=obj.style.marginRight;
			drgwi = getSize(obj, 'Width');
}

function drop(){
			drgid=false;
}


function mov(x){
	minval=mm[drgid]['minval'];
	maxval=mm[drgid]['maxval'];
	full=maxval-minval;

			obj=document.getElementById('slideract_' + drgid);
			le=parseInt(drgmal);
			ri=parseInt(drgmar);
			document.getElementById('width');
			dlt=begx-x;
			if(drgtype=='min') {
					dx = le - dlt;
					if(dx>=0 && (drgwi + dlt > 10))  {
					obj.style.marginLeft=dx + 'px';
					mv=parseInt(full/125*(dx-5) + minval);
					if(mv<minval) mv=minval;
					document.getElementById('fltn_' + drgid + '_min').value=mv;
					}

			}
			if(drgtype=='max') {
			dx=dlt+ri;
			if(dx>=0 && (drgwi - dlt > 10))  {
			obj.style.marginRight=dx + 'px';
			mv = parseInt(maxval-full/125*dx);
			if(mv>maxval) mv=maxval;
			document.getElementById('fltn_' + drgid + '_max').value=mv

			}
		}
}

document.onmousemove = mouseMove;
document.onmouseup = drop;
window.onscroll=movepaths;


function mouseMove(ev){
    ev           = ev || window.event;
    var mousePos = mouseCoords(ev);
		x=mousePos.x;
		mousex=mousePos.x;



var mCur = mousePageXY(ev);
if(spic!=false) {
	document.getElementById(spic).style.top  = (mCur.y + 40) + 'px';
	document.getElementById(spic).style.left= (mCur.x + 10) + 'px';
		}
}


function mouseCoords(ev){
    if(ev.pageX || ev.pageY){
	        return {x:ev.pageX, y:ev.pageY};
	    }
		
	return {
	        x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
	        y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	    };
}
function movep(id){
				mi = document.getElementById('fltn_' + id + '_min').value;
				ma = document.getElementById('fltn_' + id + '_max').value;
				mim = mm[id]['minval'];
				mam = mm[id]['maxval'];

			obj=document.getElementById('slideract_' + id);
			full=mam-mim;
			miv = parseInt((mi-mim)/full * 125 + 5);
			if(miv<=5) miv=0;
			obj.style.marginLeft=miv + 'px';
			mav = parseInt((mam-ma)/full * 125 + 5);
			if(mav<=5) mav=0;
			obj.style.marginRight=mav + 'px';
}

function in_array(what, where) {
    for(var i=0; i<where.length; i++)
        if(what == where[i])
            return i;
    return false;
}


function picscroll(id, dir) {
	dv = document.getElementById('picsdiv_' + id);
	cs = dv.scrollTop;
	dhe = document.getElementById('pictab').offsetHeight;;

	if(dir=='down') {	cs+=72;	}
	if(dir=='up') {	cs=cs-72;	}
			if(cs<0) {cs=0; }
			if(cs>dhe-70) {cs=dhe-70; }

			currsc = dv.scrollTop;
			slowscroll("picsdiv_" + id, currsc, cs,500, true);

			if(cs>0) document.getElementById('upa').style.display='block'; else document.getElementById('upa').style.display='none';
	if(cs+150<=dhe) document.getElementById('downa').style.display='block'; else document.getElementById('downa').style.display='none';
}


function showprice(gid, coun){
		io = couns[gid].indexOf(coun);

	for(i=0; i<gds[gid].length; i++) {
					cgid=gds[gid][i];
					pri = prcs[gid][i][io];

					dc = document.getElementById('ltd_' + cgid);
			
					if(dc)if(pri!=undefined) dc.innerHTML=pri; else dc.innerHTML = '';
					curcou[gds[gid][i]] = coun;
		}

			document.getElementById('tabb_' + gid + '_' + coun).className='actprice';
			if(coun!=curcou[gid]) document.getElementById('tabb_' + gid + '_' + curcou[gid]).className='noactprice';
		  curcou[gid]=coun;
}

spic=false;

function mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}


function showtab(id){
  document.getElementById('pardiv' ).style.display='block';
	document.getElementById('pardiv').innerHTML = document.getElementById('tpar_' + id ).innerHTML
	spic='pardiv';

}

function hidetab(id){
  document.getElementById('pardiv').style.display='none';
	spic=false;
}

function mmflt(id, type, dir){
	inp_min = document.getElementById('fltn_' + id + '_' + 'min');
	inp_max = document.getElementById('fltn_' + id + '_' + 'max');
	inp_max.disabled=false;
	inp_min.disabled=false;
	minv=inp_min.value;
	maxv=inp_max.value;
	if(type=='min') curv=minv;
	if(type=='max') curv=maxv;
	arr = mm[id]['values'];
	newval=array_smm(curv, arr, dir);

	if(type=='min') inp_min.value=Math.min(newval, maxv);
	if(type=='max') inp_max.value=Math.max(newval,minv);
}

function array_smm(what, where, mm) {
	  key=false;
		mi=0; ma=10000000;
		
		for(var i=0; i<where.length; i++){
		
if(where[i]<what && where[i]>mi) mi=where[i];
if(where[i]>what && where[i]<ma) ma=where[i];
						}
if(mi==0) mi=what;
if(ma==10000000) ma=what;
if(mm=='up') return ma;
if(mm=='down') return mi;

}

function numformat(num) {
		var newst = '';
			str = num.toString();
			
			xxx = str.split('.');
			ln = xxx[0].length;
	

		for(ii=0; ii<ln; ii=ii+3){
				pos = Math.max(ln-ii-3,0);
				nn=Math.min(3,ln-ii);
				st = xxx[0].substr(pos, nn);
				if(ii==0) spa=''; else  spa=' ';
				newst = st + spa + newst ;

}
				newst = '<span class="numformat">' + newst;

	if(xxx[1]) newst+='<sup>' + xxx[1] + '</sup>';
	newst+='</span>';
	newst+='<span class="rubstyle"> руб.</span>';
	return newst;
}

function makemo(tblid){
	
		
tb = document.getElementById(tblid);

			rows=tb.rows.length;
			rw = tb.rows[2];
			cols=rw.cells.length;



			for(r=4; r<rows; r++) {

						
			for(c=1; c<=cols; c++) {
				ce = tb.rows[r].cells[c].childNodes[0];

if(ce && ce.id)	{

			
				ce.onmouseout = function() {
				hi(this);

}
				ce.onclick=	function(){
			tl(this);
		
}

				ce.onmouseover = function() {

				sh(this);

}

	
			}
}


	}







/*

%%prices;|id='ltd_%%id;' 
onmouseover='sh(this, "%%mparams;");' 
onmouseout='hi(this)' 
onclick='tl(this, %%%id;);' 
*/
}

function closediv(){
	fdi=false;
	curid = document.getElementById('curgood').value;
	obj=document.getElementById('ltd_' + curid);
		document.getElementById('krdiv').style.display='none';
	hi(obj);

}

function chtab(id){
	for(i=0; i<tabs.length; i++) {
		tbid = 'tab' + tabs[i];
		dv = document.getElementById('div' + tbid);
		tb = document.getElementById(tbid);
		if(tbid==id) {
		dv.style.display='block';
		tb.className='vbut';
		}	 else {dv.style.display='none';
				tb.className='vbutsel';
		}
	}
}

function checkb(obj) {
	gid = obj.id.replace('cb_','');
	
	hcb=document.getElementById('hcb_' + gid);
	if(hcb.checked) {
				hcb.checked=false;
				obj.src='/images/emptybox.png';
	}
else 	{
				hcb.checked=true;
				obj.src='/images/galka.png';
	}
}

function movepics(dir){
		cont = document.getElementById("smpcont");
		sc = cont.scrollLeft;
		osc=sc;
		sc=sc+108*dir;
		slowscroll("smpcont", osc,sc,500);
}

function slowscroll(objid,b,e,secs, direc){
		obj=document.getElementById(objid);
		d=(e-b)/(secs/50);

	if(secs>0) {
			no = b+d;
			stimer = setTimeout('slowscroll("' + objid + '", ' + no + ',' + e + ','+ (secs - 50) + ',' + direc + ')',50);
			if(direc) obj.scrollTop = no; else obj.scrollLeft = no;

		} else {
			if(!direc){
				

			for(i=0; i<obj.childNodes.length;i++){
						if(obj.childNodes[i].nodeName=='DIV') di = obj.childNodes[i];
			}

			for(i=0; i<di.childNodes.length;i++){
						if(di.childNodes[i].nodeName=='TABLE') tb = di.childNodes[i];
			}
			wi = getSize(tb,'Width');
			wi2=getSize(obj, 'Width');
			sc=obj.scrollLeft;
			if(sc<=0) slowshow("big_left2", 0.3, 0.3,50); else slowshow("big_left2", 1, 1,50);
			if(sc+wi2>=wi-10) slowshow("big_right2", 0.3, 0.3,50); else slowshow("big_right2", 1, 1,50);
			}
			}
			}

function picloaded(){
			plo=true;
			document.getElementById("loadingdiv").style.display="none";
	}
	
function disppic(i){
	pict = document.getElementById('origpic');
	if(plo || (i > 2 && ie)) {
					document.getElementById("loadingdiv").style.display="none";
		pict.src=ni.src;
		pict.style.display="block";
		slowshow("origpic",0,1,200);
	}
	else {
		document.getElementById("loadingdiv").style.display="block";
		setTimeout("disppic(" + (++i) + ")",300);
		
	}
}


function tocomp(id, mflt){
			ck = getCookie('compare_' + mflt);
//	alert(ck);
			if(ck==null) cook = id;
			else{
				cgs = ck.split(',');
				n = in_array(id, cgs);
				if(n===false) {
					cgs[cgs.length] = id;
					cook=cgs;
				} else {
					c1 = document.getElementById('compara_' + cgs[n]);
					c2 = document.getElementById('comparabig_' + cgs[n]);
					c3 = document.getElementById('comparasm_' + cgs[n]);
					cgs.splice(n,1);
					if(c1) c1.innerHTML = 'К сравнению [+]';
					if(c2) c2.innerHTML = 'Добавить к сравнению [+]';
					if(c3) c3.innerHTML = 'сравнить';
					cook=cgs;
					}

}


				if(cook!='') setCookie('compare_' + mflt, cook,false, '/'); else deleteCookie('compare_' + mflt, '/');
			compar(mflt);
	}

function compar(mflt){
					ck = getCookie('compare_' + mflt);
//					alert(ck);
			if(ck!=null) {
				cgs = ck.split(',');
				for(i=0; i<cgs.length;i++){
					c1 = document.getElementById('compara_' + cgs[i]);
					c2 = document.getElementById('comparabig_' + cgs[i]);
					c3 = document.getElementById('comparasm_' + cgs[i]);
					if(c1) c1.innerHTML = 'Из сравнения [-]';
					if(c2) c2.innerHTML = 'Убрать из сравнения [-]';
					if(c3) c3.innerHTML = 'не сравнивать';


				}
					
				document.getElementById('cmpdiv').style.display='block';
				document.getElementById('cmp_count').innerHTML = cgs.length + ' ' + tovars(cgs.length);
}
			closecompare();
}

function movepaths(ev){
		sss = gscroll();
		pathd = document.getElementById('pathdiv');
		if(pathd){
	

		if(sss<189){
			pathd.style.top = (189-sss) + 'px';
}
		else pathd.style.top=0;
}
}

function closebasket(cl){
	bsk = document.getElementById('bsk_fly');
	bskc = document.getElementById('basket_close_img');
	cook = getCookie('hide_basket');
	bskt= document.getElementById('bsktd');
	if(cl)  {
		if(cook==1) cook=0; else cook=1;
	}

	if((cook!=1)) {
		bsk.style.width='150px';
		bskc.src='/images/basket_close.png';
		setCookie('hide_basket', 0, false, '/');
if(ie)		bskt.style.display = 'inline';
	
		}
		else {
			bsk.style.width='15px';	
			bskc.src='/images/basket_open.png';	
			setCookie('hide_basket', 1, false, '/');
if(ie)				bskt.style.display = 'none';

			}
}



function closecompare(cl){
	bsk = document.getElementById('cmpdiv');
	bskc = document.getElementById('compare_close_img');
	bskt= document.getElementById('cmptd');
	cook = getCookie('hide_compare');
	if(cl)  {
		if(cook==1) cook=0; else cook=1;
	}

	if((cook!=1)) {
		bsk.style.width='150px';
		bskc.src='/images/basket_close.png';
if(ie)		bskt.style.display = 'inline';
		setCookie('hide_compare', 0, false, '/');
		
	}
		else {
			bsk.style.width='15px';	
			bskc.src='/images/compare_open.png';	
			setCookie('hide_compare', 1, false, '/');
if(ie)		bskt.style.display = 'none';
	}
}


function tovars(nm){
	x = nm % 10;
	if(x==1 && nm!=11) o='товар';
	else if(x>=2 && x<=4 && nm!=12 && nm!=13 && nm!=14) o='товара';
	else o = 'товаров';
	return o;
	
	
	
}

function check_box(obj){

oid = obj.id.replace('lbl_','');
cb = document.getElementById('cb_' + oid);
im = document.getElementById('fimg_' + oid);


if(cb.checked) {
	cb.checked=false;
	im.src = '/images/emptybox_small.png';
}
else {

	im.src='/images/galka_small.png';
	cb.checked=true;
}

}

function clear_flt(fltid){
if(fltid)	{
	

	fltdiv = document.getElementById('flt_div2_' + fltid);		
	
	
			
//	alert(fltdiv.innerHTML);
			for(i=0; i<fltdiv.childNodes.length; i++){
				if(fltdiv.childNodes[i].nodeName=='TABLE') {
						tb = fltdiv.childNodes[i].id;
						flid = tb.replace('fltmm_', '');
					
					document.getElementById("fltn_" + flid + "_min").value = document.getElementById("fltn_" + flid + "_mini").value;
					document.getElementById("fltn_" + flid + "_max").value = document.getElementById("fltn_" + flid + "_maxi").value;
					
				}
				if(fltdiv.childNodes[i].checked) {
						o = fltdiv.childNodes[i];
						id=o.id.replace('cb_', '');
						o.checked=false;
						im = document.getElementById('fimg_' + id);
						im.src = '/images/emptybox_small.png';
						
						
			}
}
}

else{
	for(iii=0;iii<allfilters.length;iii++){
		clear_flt(allfilters[iii]);
	}
}
}


function shmenu(obj){
			p=obj.parentNode;
			for(i=0;i<p.childNodes.length;i++){
				pn = p.childNodes[i];
				n = pn.nodeName;

				if(n=='DIV'){
				oid =pn.id.replace('menut_','');
						if(pn==obj) {
							pn.className='headlev_2_selected'; 
							document.getElementById('menud_' + oid).style.display="block";
					}
							else {
								pn.className='headlev_2_';
								document.getElementById('menud_' + oid).style.display="none";
							}
				}
		}
	}
	
function compare_clear(mflt){
//			alert(getCookie('compare_' + mflt));
		ok = confirm("Вы уверены, что хотите очистить список сравнения ?");
		if(ok) {
			deleteCookie('compare_' + mflt, '/');
			location.href=location.href.replace('/compare', '');
	}
}

function bigpic(){
				showfull = !showfull;
				chpic2(picparams[0], picparams[1], picparams[2], picparams[3], picparams[4], false, picparams[6]);
}

function print_good(url){
		width = 800;
		height = 700;
		
		window.open(url,'',"toolbar=no,location=no,left=0,top=0,directories=no,status=yes,menubar=yes,scrollbars=no,resizable=yes,width="+width+",height="+height+""); 
}

function checkshow(){
	ck = document.getElementById('hcb_noshow');
	if(ck.checked) setCookie('hidewin',1);
	else deleteCookie('hidewin');
}
