function openWin(winTitle, winUrl, imgWidth, imgHeight, maxImgWidth, maxImgHeight, winBgColor) {
	
	winWidth 	= imgWidth;
	winHeight	= imgHeight;
	resizeFact	= parseInt(imgHeight / imgWidth);
	
	// horizontal resize if needed
	if (winWidth > maxImgWidth) {
		winWidth 	= maxImgWidth;
		winHeight 	= resizeFact * winWidth;
	}
	
	// vertical resize if needed
	if (winHeight > maxImgHeight) {
		winHeight 	= maxImgHeight;
		winWidth 	= parseInt(winHeight / resizeFact);
	}

	winLeft = parseInt((screen.width - winWidth)/10 );
	winTop = parseInt((screen.height - winHeight)/1.2 );
	if(winBgColor) {
		imgWidth = winWidth;
		imgHeight = winHeight;
		winWidth = winWidth + 70;
		winHeight = winHeight + 70;
	}
	winProps = 'width=' + winWidth + ',height=' + winHeight + ',top=' + winTop + ',left=' + winLeft + ',resizable=1,scrollbars=1,status=1';
	
	if(winBgColor){
		myWin = window.open("", winTitle, winProps);
		myWin.document.open();
		myWin.document.write('<body bgcolor="' + winBgColor + '" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><a href="javascript:window.close()"><img src="' + winUrl +'" width="' + imgWidth + '" height="' + imgHeight + '" border="0" alt="Click to close window" title="Inchide fereastra"></a></td></tr></table></body>');
		myWin.document.close();
	}
	else myWin = window.open(winUrl,winTitle,winProps);
	
	myWin.resizeTo(winWidth, winHeight);
	myWin.moveTo(winLeft, winTop);
	myWin.focus();
}

