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

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; }
		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) {
	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, sUserFeatures) {
	var iWinWidth = iImgW + 20;
	var iWinHeight = iImgH + 20;
	var sAllFeatures = sUserFeatures + getPopupSizeRelatedFeatures(iWinWidth, iWinHeight, sUserFeatures);
	sAllFeatures += getStdFeatures(sAllFeatures);
	var sWinName = (strUserWinName)? strUserWinName : 'popupWin';
	var popupWin = window.open('', sWinName, sAllFeatures);
	if (popupWin) {
		popupWin.document.open();
		popupWin.document.write('<html><head><title>' + sWinTitle + '</title>');
		popupWin.document.write('</head><body bgcolor="white" style="margin: 0px; padding: 0px;">');
		popupWin.document.write('<img src="' + sImgSrc + '" alt="" style="margin: 10px" />');
		popupWin.document.write('</body></html>');
		popupWin.document.close();
		popupWin.focus();
	}
	return false;
}

function openWnd(url,w,h){
	w=(w?w:850);
	h=(h?h:700);
	var wnd=window.open(url,"win","width="+w+",height="+h+",scrollbars=1,toolbar=0,menubar=0,history=0,resizable=1");
	wnd.window.focus();
	return false;
}
