

function OpenThumbnail(xiUserId, xiAttachmentId, xstrDateLine, xstrSession)
{
	var me = this;

	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{		
			strAd = 'no';
			iImgWidth = 0;
			iImgHeight = 0;		
			bScrollBars = false;
			bResizable = false;
			iAdHeight = 0;
			iAdWidth = 0;		

			aImg = me.xml_sender.handler.responseText.split(",");
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
			if(aImg.length > 1)
			{
				iImgWidth = parseInt(aImg[0]);
				iImgHeight = parseInt(aImg[1]);
			}

			iMaxWidth = screen.availWidth;
			iMaxHeight = screen.availHeight;		
			if((iImgWidth == 0) || (iImgHeight == 0))
			{
				iImgWidth = 800;
				iImgHeight = 600;
				bScrollBars = true;
				bResizable = true;			
			}
			iWinWidth = iImgWidth + 4;
			iWinHeight = iImgHeight + 4;
	
			if((iMaxWidth == 0) || (iMaxHeight == 0))
			{
				iMaxWidth == 800;
				iMaxHeight == 600;
				bScrollBars = true;
				bResizable = true;
			}
			if(bScrollBars)
			{
				iWinWidth += 10;
				iWinHeight += 10;
			}
			
			if((iWinWidth + 10 > iMaxWidth) || (iWinHeight + 40 > iMaxHeight))
			{
				if(iWinWidth + 10 > iMaxWidth)
				{
					iWinWidth = iMaxWidth - 10;
					iWinHeight += 16;   // scrollbars
				}
				if(iWinHeight + 10 > iMaxHeight)
				{
					iWinHeight = iMaxHeight - 10;
					iWinWidth += 16;	// scrollbars; 
				}
				if(iWinWidth + 10 > iMaxWidth) iWinWidth = iMaxWidth - 10;
				bScrollBars = true;
				bResizable = true;		
			}
	        else
	        {
				if((iWinHeight + 110 <= iMaxHeight) && (iImgWidth >= 750))
				{
					strAd = 'bt';
					iAdHeight = 110;
					iWinHeight += 110;
				}
				else
				if((iWinWidth + 170 <= iMaxWidth) && (iImgHeight >= 600))
				{
					strAd = 'br';
					iAdWidth = 170;
					iWinWidth += 170;
				}
				else
				if((iWinWidth + 170 <= iMaxWidth) && (iImgHeight >= 284)) 
				{
			 		strAd = 'sr';
			 		iAdWidth = 170;
			 		iWinWidth += 170;
				}
				else
				if(iWinHeight + 70 <= iMaxHeight) 
				{
					strAd = 'st';
					iAdHeight = 70;   			
					iWinHeight += 70;
					if(iWinWidth < 476) iWinWidth = 476;		
				}
			}				
	
			strUrl = 'attachwin.php?';
			strUrl += 'aid=' + xiAttachmentId + '&d=' + xstrDateLine;
			strUrl += '&ad=' + strAd;
			if(iAdHeight > 0) 
			{
				strUrl += '&adh=';
				strUrl += iAdHeight;
			}
			if(iAdWidth > 0) 
			{
				strUrl += '&adw=';
				strUrl += iAdWidth;
			}
			strWinName = 'attachment' + xiAttachmentId;
			strOptions = 'width=' + iWinWidth + ',height=' + iWinHeight;
			strOptions += ',resizable=' + (bResizable ? 'yes' : 'no');
			strOptions += ',status=no,menubar=no,toolbar=no,scrollbars=';
			strOptions += (bScrollBars ? 'yes' : 'no');
			window.open(strUrl, strWinName, strOptions).focus();
		}
	}
	
	this.xml_sender = new vB_AJAX_Handler(true);
	this.xml_sender.onreadystatechange(this.onreadystatechange);
	this.xml_sender.send('ajax.php', 'do=openattachment&a=' + xiAttachmentId + '&u=' + xiUserId);
	
}	
	
