var arrStdPopupFeatures = [
	['menubar', 'no'],
	['toolbar', 'no'],
	['resizable', 'yes'],
	['scrollbars', 'yes'],
	['status', 'yes']
]

function getStdFeatures( strUserFeatures ) {
	var strStdFeatures = '';
	for ( var i = 0; i < arrStdPopupFeatures.length; i++) {
		if ( !(strUserFeatures && strUserFeatures.indexOf( arrStdPopupFeatures[i][0] ) >= 0 ) ) {
			strStdFeatures += ',' + arrStdPopupFeatures[i][0] + '=' + arrStdPopupFeatures[i][1];
		}
	}
	return strStdFeatures;
}

function getPopupSizeRelatedFeatures( iWinW, iWinH, strUserFeatures ) {
	var strSizeRelatedFeatures = '';
	var iWinWidth = ( iWinW )? iWinW : 540;
	var iWinHeight = ( iWinH )? iWinH : 600;
	if ( screen ) {
		var iScrWidth = ( screen.width )? screen.width : 0;
		var iScrHeight = ( screen.height )? screen.height : 0;
		var bNeedScroll = false;
		if ( iScrWidth < iWinWidth + 50 ) { bNeedScroll = true; iWinWidth = iScrWidth - 50; iWinHeight += 16; }
		if ( iScrHeight < iWinHeight + 100 ) { bNeedScroll = true; iWinHeight = iScrHeight - 100; iWinWidth += 16; }
		if ( !(strUserFeatures && strUserFeatures.indexOf('scrollbars') >= 0 ) ) {
			strSizeRelatedFeatures += ( bNeedScroll )? ',scrollbars=yes' : ',scrollbars=no';
		}
		var iPosX = Math.round( ( iScrWidth - iWinWidth ) / 2 );
		var iPosY = Math.round( ( ( iScrHeight - 70 ) - iWinHeight ) / 2);
		strSizeRelatedFeatures += ( document.all )? ',left=' + iPosX + ',top=' + iPosY : ',screenX=' + iPosX + ',screenY=' + iPosY;
	}
	strSizeRelatedFeatures += ',width=' + iWinWidth + ',height=' + iWinHeight;

	return strSizeRelatedFeatures;
}

function popup(strFileUrl, strUserWinName, iWinW, iWinH, strUserFeatures) {
	var strAllFeatures = strUserFeatures + getPopupSizeRelatedFeatures( iWinW, iWinH, strUserFeatures );
	strAllFeatures += getStdFeatures( strAllFeatures );
	var strWinName = ( strUserWinName )? strUserWinName : 'popupWin';
	var popupWin = window.open(strFileUrl, strWinName, strAllFeatures);
	if ( popupWin ) popupWin.focus();
}

function popupImg( sImgSrc, strUserWinName, iImgW, iImgH, sWinTitle, strUserFeatures, sAdditionalHTML, iWinW, iWinH ) {
	if (!iWinW) iWinW = iImgW + 20;
	if (!iWinH) iWinH = iImgH + 20;
	var strAllFeatures = strUserFeatures + getPopupSizeRelatedFeatures(iWinW, iWinH, strUserFeatures);
	strAllFeatures += getStdFeatures(strAllFeatures);
	var strWinName = (strUserWinName)? strUserWinName : 'popupWin';
	var popupWin = window.open('', strWinName, strAllFeatures);
	if (popupWin) {
		popupWin.document.open();
		popupWin.document.write('<html><head><title>' + sWinTitle + '</title></head><body bgcolor="white" style="margin: 0px; padding: 0px;"><table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td align="center">');
		popupWin.document.write('<img src="' + sImgSrc + '" width="' + iImgW + '" height="' + iImgH + '" onclick="window.close();" style="cursor: pointer; cursor: hand;" />');
		if (sAdditionalHTML) popupWin.document.write(sAdditionalHTML);
		popupWin.document.write('</td></tr></table></body></html>');
		popupWin.document.close();
		popupWin.focus();
	}
	return false;
}
