function put2basket (url) {
            	w = window.open(url, 'basket','status=no,scrollbars=yes,width=650,height=450');
             	if (w) w.focus ();
              };
function basket(i){

  if (form['order_'+i].value>0)
  {
   goUrl = "basket?basket=1"+"&id="+form['id_'+i].value+"&order=" + form['order_'+i].value + "&razmer="+form['size_'+i].value;
   put2basket(goUrl);
  }
}

function proverka(i)
{
 if(document.form['order_'+i].value>SizeQty(i))
 {
  alert('Столько нет в наличии');
 }
 else
 {
  basket(i);
 }
}

function SizeQty(i)
{
 size=document.form['size_'+i].value;
 return document.form['s'+i+'_'+size].value;
}

function showimg(img)
{
	w = window.open('merchimg/'+img, '','status=no,scrollbars=yes,width=500,height=330');
    if (w) w.focus ();
}

var objheight;
var objwidth;

function showBigPic(image) 
{  
   
	objheight = 310;
	objwidth = 480;	
	var podol = document.createElement("div");
	var win = document.createElement("div");

	win.setAttribute("id", "bigpic");
	podol.setAttribute("id", "podol");
	document.body.appendChild(podol);
	document.body.appendChild(win);
	
	
	podol.style.visibility = 'visible';
	podol.style.display = 'block';
	podol.style.width = getDocumentWidth() + 'px';
	podol.style.height = getDocumentHeight()  + 'px';

	win.style.visibility = 'visible';
	win.style.display = 'block';
	wtop  = getClientCenterY() - 16 + "px";
	wleft = getClientCenterX() - 16 + "px";
	win.style.top = wtop;
	win.style.left = wleft;

	win.innerHTML = "<img src='pictures/loading.gif' id='loading' ><img width=0 height=0 src='merchimg/" + 
	image + "' id='bigimg'  onLoad='PicOnLoad("+ objwidth+","+objheight+")'>";


	win.onmousedown = closePic;
	podol.onmousedown = closePic;

	setElementOpacity("podol", 0.5);

	
	if(document.body.scroll != null) {// для ie
		document.body.setAttribute("scroll", "no");
		InputLayer();
	} else {
		window.onscroll = notscroll; 
	}
	
}

function PicOnLoad(width, height) {
    win = document.getElementById("bigpic");
    wtop  = getClientCenterY() - parseInt((height + 2)/2) + "px";
	wleft = getClientCenterX() - parseInt((width + 2)/2)  + "px";
	win.style.top = wtop;
	win.style.left = wleft;
	loadpic = document.getElementById("loading");
	loadpic.style.width =  0;
	loadpic.style.height = 0;
	animate('bigimg');
}

function notscroll(top, left) {
	win = document.getElementById('bigpic');
	wtop  = getClientCenterY() - parseInt((objheight + 2)/2) + "px";
	wleft = getClientCenterX() - parseInt((objwidth + 2)/2)  + "px";
	win.style.top = wtop;
	win.style.left = wleft;
}

function InputLayer() {
	selectlist = document.body.getElementsByTagName('select');
	for (var i=0;i<selectlist.length;i++)
	{
		el = selectlist[i];
		if (el.style.visibility != 'hidden') {
		  el.style.visibility = 'hidden';
		}  else {
		  el.style.visibility = 'visible';
		}

	}
}

function closePic() 
{
	if(document.getElementById('bigpic')) {
		win = document.getElementById('bigpic');
	}

	if(document.getElementById('podol')) {
		p = document.getElementById('podol');
	}

	if(document.getElementById('bigimg')) {
		big = document.getElementById('bigimg');
	}
	
	if(document.getElementById('loading')) {
		load = document.getElementById('loading');
	}
   
	if(document.body.scroll) {
		document.body.setAttribute("scroll", "");
		InputLayer();
		big.removeNode();
		load.removeNode();
		win.removeNode();
		p.removeNode();
	} else {
		win.removeChild(load);
		win.removeChild(big);
		document.body.removeChild(win);
		document.body.removeChild(p);
		window.onscroll = ""; 
	}
}

//
//
//
function animate(id, dur) {
		var element = document.getElementById(id);
		var heightfrom = 0;
		var widthfrom = 0;
		var to = 500;
		var duration = dur || 1000;
		var start = new Date().getTime();

		setTimeout(function() {
		    var now = (new Date().getTime()) - start;
		    var progress = now / duration;
			if (progress > 1) {
		        var resWidth = objwidth;
				var resHeight = objheight;
			}else { 
				var resWidth  = (objwidth - widthfrom) * progress + widthfrom;
				var resHeight = (objheight - heightfrom) * progress + heightfrom;
			}

		    element.style.width = resWidth + "px";
			element.style.height = resHeight + "px";

		    if (progress < 1)
		        setTimeout(arguments.callee, 10);
		}, 100);
}



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 getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}


function setElementOpacity(sElemId, nOpacity)
{
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);

  if (!elem || !opacityProp) return; 
  
  if (opacityProp=="filter")  
  {
    nOpacity *= 100;
	
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
  }
  else
    elem.style[opacityProp] = nOpacity;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
    return 'filter';

  return false;
}

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 getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}
