/*****************************
**   P o p u p s
**   standard methods
******************************/

var arrStdPopupFeatures = {
	menubar: 'no',
	toolbar: 'no',
	location: 'no',
	resizable: 'yes',
	scrollbars: 'yes',
	status: 'yes'
}

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

function getPopupSizeRelatedFeatures( iWinW, iWinH, strUserFeatures ) {
	var strSizeRelatedFeatures = 'directories=no';
	var iWinWidth = ( iWinW )? iWinW : 600;
	var iWinHeight = ( iWinH )? iWinH : 600;
	if ( screen ) {
		var iScrWidth = ( screen.width )? screen.width : 0;
		var iScrHeight = ( screen.height )? screen.height : 0;
		var bNeedScroll = (arrStdPopupFeatures.scrollbars == 'no')? false : true;
		if ( iScrWidth < iWinWidth + 50 ) { bNeedScroll = true; iWinWidth = iScrWidth - 50; }
		if ( iScrHeight < iWinHeight + 100 ) { bNeedScroll = true; iWinHeight = iScrHeight - 100; }
		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) {
	if (!strUserFeatures) 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:0; padding:0;"><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 + '" />');
		if (sAdditionalHTML) popupWin.document.write(sAdditionalHTML);
		popupWin.document.write('</td></tr></table></body></html>');
		popupWin.document.close();
		popupWin.focus();
	}
	return false;
}
