/* functii pentru deschiderea de ferestre modale
   - se includ in paginile care deschid ferestrele modale*/

var childWin;
/*
if( self.document.body != null )
	self.document.body.onFocus = focusChildIfAny();
else if( self.parent.document.body != null )
	self.parent.document.body.onFocus = focusChildIfAny();
*/
function focusChildIfAny()
{
	if( childWin != null )
	{
		try{
			childWin.focus();
		}catch( e ){}
	}
	return true;
}

function openModalChild( url, name, attribute )
{
	// Dimensiunile ecranului
	var wsw = window.screen.availWidth;		//screen.availWidth;
	var wsh = window.screen.availHeight;	//screen.availHeight;

	// daca are atributele width si height dar lipsesc atributele left si top, centreaza fereastra
	if( ( attribute.indexOf( "width" ) != -1 && attribute.indexOf( "height" ) != -1 ) &&
		( attribute.indexOf( "left" ) == -1 || attribute.indexOf( "top" ) == -1 ) )
	{
		width = parseInt( attribute.substring( attribute.indexOf( "width" ) + 6, attribute.indexOf( ",", attribute.indexOf( "width" ) ) ) );
		height = parseInt( attribute.substring( attribute.indexOf( "height" ) + 7, attribute.indexOf( ",", attribute.indexOf( "height" ) ) ) );
		var myArrtibutes = 'left=' + (wsw - width)/2 + ',top=' + (wsh-height)/2 + ',';
		attribute = myArrtibutes + attribute;
		childWin = window.open( url, name, attribute );
		childWin.focus();
	}
	// daca are atributele left si top dar lipsesc atributele width si height, dimensioneaza fereastra a.î. sa fie centrata
	else if( ( attribute.indexOf( "left" ) != -1 && attribute.indexOf( "top" ) != -1 ) &&
			 ( attribute.indexOf( "width" ) == -1 || attribute.indexOf( "height" ) == -1 ) )
	{
		left = parseInt( attribute.substring( attribute.indexOf( "left" ) + 5, attribute.indexOf( ",", attribute.indexOf( "left" ) ) ) );
		top_size = parseInt( attribute.substring( attribute.indexOf( "top" ) + 4, attribute.indexOf( ",", attribute.indexOf( "top" ) ) ) );
		var myArrtibutes = 'width=' + (wsw - 2*left) + ',height=' + (wsh - 2*top_size) + ',';
		attribute = myArrtibutes + attribute;
		childWin = window.open( url, name, attribute );
		childWin.focus();
	}
	// daca lipseste unul dintre atributele left, top, width, height redimensioneaza fereastra
	else if( attribute.indexOf( "left" ) == -1 || attribute.indexOf( "top" ) == -1 ||
		attribute.indexOf( "width" ) == -1 || attribute.indexOf( "height" ) == -1 )
	{
		var myArrtibutes = 'left=30,top=30,width=' + ( wsw - 60 ) + ',height=' + ( wsh - 60 ) + ',';
		attribute = myArrtibutes + attribute;
		childWin = window.open( url, name, attribute );
		childWin.resizeTo( wsw - 60, wsh - 60 );
		childWin.focus();
	}
	// daca are atributele left, top, width si height nu face nici o modificare
	else
	{
		childWin = window.open( url, name, attribute );
		childWin.focus();
		//self.setTimeout( "_clearAlphaFilter()", 1000 );
	}
	return childWin;
}

function _getValidModalDependent()
{
	if( childWin != null )
	{
		if( childWin.closed )
			childWin = null;
	}
	return childWin;
}

function _clearAlphaFilter()
{
	var a1 = _getValidModalDependent();
	if( a1 != null )
	{
		if( self.document.hasFocus() )
			focusChildIfAny();
		self.setTimeout( "_clearAlphaFilter()", 1000 );
	}
	else
	{
		self.document.body.style.filter = null;
		self.document.body.releaseCapture();
		self.document.body.style.cursor = "auto";
	}
}

