function WinPreview(id){
 	document.body.scrollTop = document.body.scrollTop <= 500 ? 500 : document.body.scrollTop;
 	if (document.all){
  		document.body.scroll = "no";
  	}
   	else{
    	var oTop = document.body.scrollTop;
     	document.body.style.overflow = "hidden";
      	document.body.scrollTop = oTop;
    }

	var width = galleryList[id][1];
	var height = galleryList[id][2];
	bWidth = document.body.clientWidth;
	bHeight = document.body.clientHeight;
	if(width > bWidth){
		height = (bWidth / width) * height;
		width = bWidth;
	}

	if(height >= bHeight - 50){
		bHeight = bHeight - 50;
		width = (bHeight / height) * width;
		height = bHeight;
	}

	var top = document.body.scrollTop + 10;
	var left = (document.body.clientWidth  - width) / 2;
	//alert(document.body.clientHeight +' = '+height);
	/*
	if(width > height){
		bWidth = document.body.clientWidth - 240;
		if(width >= bWidth){
			height = (bWidth / width) * height;
			width = bWidth;
		}
		var top = document.body.scrollTop + 10;
		var left = (document.body.clientWidth  - width) / 2;
	}
	else{
		bHeight = document.body.clientHeight - 240;
		if(height >= bHeight){
			width = (bHeight / height) * width;
			height = bHeight;
		}
		var top = document.body.scrollTop + 5;
		var left = (document.body.clientWidth  - width) / 2;
	}
    alert(document.body.clientHeight +' = '+height);
    */
	// Create background

	var Bgd = document.getElementById("bgWnd");
    if(!Bgd){
        Bgd = document.createElement("DIV");
        Bgd.id = "bgWnd";
        Bgd.style.border = "1px solid #666666";
        Bgd.style.position = "absolute";
        Bgd.style.overflow = "hidden";
        Bgd.style.zIndex = "998";
        Bgd.style.display = "none";
        document.body.appendChild(Bgd);
    }
    Bgd.style.left = 0;
    Bgd.style.top = 0;
    Bgd.style.width = "100%";
    Bgd.style.height = "10000";
    Bgd.style.background = "url('/images/black.png')";
    //Bgd.style.background = "#000000";
    Bgd.style.display = "block";
    Bgd.style.padding = 0;
    Bgd.style.textAlign = "left";
    Bgd.style.filter = "alpha(Opacity=90)";

    // Create Image
    var Wnd = document.getElementById("popupWnd");
    if(!Wnd){
        Wnd = document.createElement("DIV");
        Wnd.id = "popupWnd";
        Wnd.style.border = 0;
        Wnd.style.position = "absolute";
        //Wnd.style.overflow = "hidden";
        Wnd.style.zIndex = "999";
        Wnd.style.display = "none";
        document.body.appendChild(Wnd);
    }
    Wnd.style.left = left;
    Wnd.style.top = top;
    Wnd.style.width = width;
    //Wnd.style.height = height;
    //Wnd.style.background = "#FFFFFF";
    Wnd.style.display = "block";
    Wnd.style.padding = 0;
    Wnd.style.textAlign = "left";

    var next = id + 1;
    var prev = id - 1;
    next = (next == galleryList.length) ? 0 : next;
    prev = (prev < 0) ? galleryList.length - 1 : prev;

    var cnt = '';

    cnt += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>';
    cnt += '<div style="color:white; font: bold 11px Arial;"><nobr>' + galleryList[id][3] + '</nobr></div>';
    cnt += '</td><td>';
    cnt += '<div style="widht:'+width+'px; height:20px; text-align:right;"><nobr>';
    if(galleryList.length > 1){
    cnt += ' <a href="#" onclick="WinPreview('+prev+');return false;" title="Предыдущая"><img src="/images/gallery/previous.gif" border="0"></a> ';
    cnt += ' <a href="#" onclick="WinPreview('+next+');return false;" title="Следующая"><img src="/images/gallery/next.gif" border="0"></a> ';
    }
    cnt += ' <a href="#" onclick="CloseWinErr(\'popupWnd\'); return false;" title="Закрыть"><img src="/images/gallery/close.gif" border="0"></a> ';
    cnt += '</nobr></div>';
    cnt += '</td></tr></table>';
    cnt += '<div onclick="WinPreview('+next+');" style="cursor:pointer;"><img src="' + galleryList[id][0] + '" width="' + width + '" height="' + height + '" border="0" alt="' + galleryList[id][3] + '"></div>';
    //onclick="CloseWinErr(\'popupWnd\');" style="cursor:pointer;"
    Wnd.innerHTML = cnt;
    if(document.attachEvent){
		document.attachEvent('onmousewheel', mScrollBody);
	}
	else if(document.addEventListener){
		document.addEventListener('scroll', mScrollBody, true);
	}

}



function CloseWinErr(id){
	var ErrObj = document.getElementById(id) ? document.getElementById(id) : document.all[id];
	var bgObj = document.getElementById('bgWnd') ? document.getElementById('bgWnd') : document.all['bgWnd'];
	if(ErrObj){
		ErrObj.style.display = "none";
	}
	if(bgObj){
		bgObj.style.display = "none";
	}
	if (document.all){
  		document.body.scroll = "yes";
  	}
   	else{
    	var oTop = document.body.scrollTop;
     	document.body.style.overflow = "";
      	document.body.scrollTop = oTop;
    }
    if(document.attachEvent){
		document.attachEvent('onmousewheel', mScrollBodyOpen);
	}
	else if(document.addEventListener){
		document.removeEventListener('scroll', mScrollBody, true);
	}
}

function mScrollBody(){
	return false;
}
function mScrollBodyOpen(){
	return true;
}
function WichOneChecked(radio_name) // Функция, определаяющая значение радио-кнопок
{
        for_text = "for (i=0; i<document.calc_form." + radio_name + ".length;i++)\n{\nif (document.calc_form." + radio_name + "[i].checked==true) radio_val=document.calc_form." + radio_name + "[i].value;}\n";
        eval (for_text);
        return radio_val;
}