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

var arrStdPopupFeatures = [
	['menubar', 'no'],
	['toolbar', 'no'],
	['resizable', 'no'],
	['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 - 560; }
		if ( iScrHeight < iWinHeight + 100 ) { bNeedScroll = true; iWinHeight = iScrHeight - 600; }
		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(); return false } else return true;

}

function getLang()
{
	var arrPath = window.location.href.split('/');
	
	return (arrPath[3]) ? arrPath[3] : 'ru';
}

function popupImg( strImgSrc, strUserWinName, iImgW, iImgH, strWinTitle, strUserFeatures )
{
	//alert('[' + iImgW + ':' + typeof(iImgW) + ' - ' + iImgH + ':' + typeof(iImgH) + ']');

	var strAllFeatures = strUserFeatures + getPopupSizeRelatedFeatures( iImgW + 20, iImgH + 60, 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>' + strWinTitle + '</title></head><body bgcolor="white" style="margin: 0px; padding: 0px;"><table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td bgcolor="#ebebeb" align="center">')
		popupWin.document.write('<img src="' + strImgSrc + '" width="' + iImgW + '" height="' + iImgH + '" />')
		popupWin.document.write('</td></tr><tr><td style="height:25px; vertical-align:middle;" bgcolor="white" align="center"><a href="javascript:self.close();"><img border="0" src="/img/' + getLang() + '/popup-close.gif"/></a></td></tr></table></body></html>')
		popupWin.document.close();
		popupWin.focus();
	}
	return false;
}