var col=0;
var image=new Array();
// Open Screenshot page
function PopUpOpen(picsrc, x, y, comment, ihtml)
{
  //
  var maxWidth=screen.availWidth;
  var maxHeight=screen.availHeight;

  var needWidth = x + 10;
  var needHeight = y + 80;

  var scrollbars = 'no';
  if(needWidth > maxWidth) {
    winWidth = maxWidth;
    scrollbars = 'yes';
  } else winWidth = needWidth;
  if(needHeight > maxHeight) {
    winHeight = maxHeight; 
    scrollbars = 'yes';
  }else winHeight = needHeight;

  //alert(winWidth + ' x ' + winHeight);
  var left = screen.availWidth/2 - winWidth/2;
  if(left < 0) left = 5;
  var top = screen.availHeight/2 - winHeight/2;
  if(top < 0) top = 5;

  if (document.layers) {
   image=window.open('','img','toolbar=no,location=0,directories=no,menubar=0,height='+winHeight+',width='+winWidth+', top=' + top + ', left=' + left +', resizable=yes,scrollbars=' + scrollbars);
   image.document.open();
   image.document.write('<html><head><title>Image</title><script>window.resizeTo('+winWidth+', '+winHeight+')</script></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><center><table height=100% cellpadding=0 cellspacing=0 border=0><tr><td align=center><a href=# onclick=\"window.close()\"><img id="picture" style="border: 0px Black Solid; padding: 1px;" src="' + picsrc + '" width=' + x + ' height = ' + y + ' alt="Кликните, чтобы закрыть окно" vspace=5></a><br><font size=-1>' + comment + '</font></td></tr></table></center></body></html>');
   image.focus();
  } else {
   if (col>0) {image[col-1].close();}

   image[col]=window.open('','img'+col,'toolbar=no,location=0,directories=no,menubar=0,height='+winHeight+',width='+winWidth+', top=' + top + ', left=' + left +', resizable=yes,scrollbars=' + scrollbars);
   image[col].document.open();
   image[col].document.write('<html><head><title>' + comment + '</title><link rel=stylesheet href=img/main.css type=text/css></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 bgcolor=#F0F0F0><table align=center height=100% cellpadding=0 cellspacing=0 border=0><tr><td align=center><div class="tyretype2">'+ comment +'</div></td></tr></table><script>if(navigator.appName != \'Opera\' || navigator.appName == \'Opera\' && navigator.appVersion >= \'7\') window.resizeTo('+winWidth+', '+winHeight+')</script></body></html>');
   image[col].focus();
   col=col+1;
  }
  if(ihtml == 1) window.location.reload();
}

function winOpen(url)
{
	var iWidth = 500;
	var iHeight = 600;
	var iTitle = 'www.Tyre.in.ua';
	var scrollB = 'yes';
	var posCode = '';

	if(screen) {
		var scrW = screen.width ? screen.width - 100 : 0;
		var scrH = screen.height ? screen.height - 100 : 0;
		if( scrW < iWidth ) { scrollB = 'yes'; iWidth = scrW; }
			else { scrW = screen.width }
		if( scrH < iHeight ) { scrollB = 'yes'; iHeight = scrH; }
			else { scrH = screen.height }
		var posX = Math.round( ( scrW - iWidth ) / 2 );
		var posY = Math.round( ( scrH - iHeight ) / 2 );
		posCode = ',left='+posX+',top='+posY;
	}
	iOptions = 'width=500,height=600,scrollbars=' + scrollB + ',resizable=no,toolbar=no,status=yes' + posCode;

window.open(url, '_blank', iOptions);	
}

function winOpenImg(url)
{
	var iWidth = 235;
	var iHeight = 325;
	var iTitle = 'www.Tyre.in.ua';
	var scrollB = 'no';
	var posCode = '';

	if(screen) {
		var scrW = screen.width ? screen.width - 100 : 0;
		var scrH = screen.height ? screen.height - 100 : 0;
		if( scrW < iWidth ) { scrollB = 'yes'; iWidth = scrW; }
			else { scrW = screen.width }
		if( scrH < iHeight ) { scrollB = 'yes'; iHeight = scrH; }
			else { scrH = screen.height }
		var posX = Math.round( ( scrW - iWidth ) / 2 );
		var posY = Math.round( ( scrH - iHeight ) / 2 );
		posCode = ',left='+posX+',top='+posY;
	}
	iOptions = 'width=235,height=325,scrollbars=' + scrollB + ',resizable=no,toolbar=no,status=yes' + posCode;

window.open(url, '_blank', iOptions);	
}

function winOpenMap(url)
{
	var iWidth = 1000;
	var iHeight = 733;
	var iTitle = 'www.Tyre.in.ua';
	var scrollB = 'no';
	var posCode = '';

	if(screen) {
		var scrW = screen.width ? screen.width - 100 : 0;
		var scrH = screen.height ? screen.height - 100 : 0;
		if( scrW < iWidth ) { scrollB = 'yes'; iWidth = scrW; }
			else { scrW = screen.width }
		if( scrH < iHeight ) { scrollB = 'yes'; iHeight = scrH; }
			else { scrH = screen.height }
		var posX = Math.round( ( scrW - iWidth ) / 2 );
		var posY = Math.round( ( scrH - iHeight ) / 2 );
		posCode = ',left='+posX+',top='+posY;
	}
	iOptions = 'width=1000,height=733,scrollbars=' + scrollB + ',resizable=no,toolbar=no,status=yes' + posCode;

window.open(url, '_blank', iOptions);	
}


function elm_class(obj, nm) 
{
	if (typeof(obj) != 'object') 
	{
		return;
	}
	try 
	{
		obj.className = nm;
	}
	catch (e)
	{}
}

//Прятать лишнее под слоями
function toggleDisplay(tag, value, cont)
{
	if (!cont)
		cont = document;
	var sel = document.getElementsByTagName(tag);
	for (var i = 0; i < sel.length; i++)
		sel[i].style.visibility = value;
}
//Картинки
function showpic(picurl,w,h,act){
	var m = document.getElementById('FloatMaskLogin')
	var l = document.getElementById('fotodiv')
	if(act==1){
		l.style.display = 'none';
		m.style.display = 'none';
		toggleDisplay('SELECT', 'visible');
		toggleDisplay('OBJECT', 'visible');
		toggleDisplay('EMBED', 'visible');
		toggleDisplay('IFRAME', 'visible');
	}else{
		toggleDisplay('SELECT', 'hidden');
		toggleDisplay('OBJECT', 'hidden');
		toggleDisplay('EMBED', 'hidden');
		toggleDisplay('IFRAME', 'hidden');
		m.style.display = 'block';
		m.style.height = document.body.scrollTop + document.body.offsetHeight + 'px';
		l.innerHTML='<a href="#" onclick="showpic(\'\',\'\',\'\',1); return false;"><img style="position:relative" class=border3 id=showfotoobj src='+picurl+' width='+w+' height='+h+' border=0>';
		var lW = w;
		var lH = h;
		var sW = (!b.ie) ? self.innerWidth : self.document.body.offsetWidth;
		var sH = (!b.ie) ? self.innerHeight : self.document.body.offsetHeight;
		l.style.width = lW + px;
		l.style.left = (document.body.scrollLeft + (sW - lW)/2) + px;
		l.style.top = (document.body.scrollTop + (sH - lH-25)/2) + px;
		
		l.style.display = 'block';
	}
	return false;
}