var MARGIN_HEIGHT = 60,
    MARGIN_WIDTH = 30;

function releaseNumber( navig )

{

 var version;

 version = navig.appVersion;
 
 return version.substring( 0, version.indexOf("(") );

}

function openWindow( name, url, width, height, x, y, focus )

{
 
 var win;

 if ( width == null )
   
   {

	width = screen.width / 2;
    
   }

 if ( height == null )
   
   {

	height = screen.height / 2;
    
   }

 if ( x == null )

   
   {

    x = 1;

   }

 if ( y == null )

   
   {

    y = 1;

   }
 
 if ( focus == null )

   {
     
    focus = true;

   }


 if ( releaseNumber( navigator ).charAt(0) >= "4" )/*Navigateurs version 4.XX*/ 

   {
    
	if ( navigator.appName.indexOf("Microsoft") >= 0 )//Pour Microsoft Internet Explorer
   
      {
   
	   position = ",left=" + x + ",top=" + y;
   
      }
 
    else//Pour Netscape
   
      {
   
	   position =",screenX=" + x + ",screenY=" + y;
   
      }
    win = window.open( url,name,"status=yes,dependent=yes,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + position );
   
    //win = window.open( url,name,"dependent=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + position );

   }

 else
   
   {
    
    win = window.open( url,name,"dependent=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes");
    //win = window.open( url,name,"dependent=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
   
   } 	
 
 if ( focus )
   
   {
   
    win.focus();

   }

 //return win;

}

function openSimpleWindow( name, url, width, height, x, y )
{

 if ( width == null )
   
   {

	width = screen.width / 2;
    
   }

 if ( height == null )
   
   {

	height = screen.height / 2;
    
   }

 if ( x == null )

   
   {

    x = 1;

   }

 if ( y == null )

   
   {

    y = 1;

   }

// user_pref("signed.applets.codebase_principal_support", true);
 
 //win = window.open( url,name,"titlebar=no,alwaysRaised=yes,dependent=yes,toolbar=no,location=no,directories=no,status=no,personalbar=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + ",left=" + x + ",top=" + y );
 win = window.open( url,name,"titlebar=no,alwaysRaised=yes,dependent=yes,toolbar=no,location=no,directories=no,personalbar=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + ",left=" + x + ",top=" + y );

 win.focus();

}

function openTopRightWindow( name, url, width, height )

{

 var x,
	 y = 1;

 x = screen.availWidth - width;

 openWindow( name, url, width, height, x, y );
 
}

function openFullScreenWindow( name, url )

{

 var win;

 if ( releaseNumber( navigator ).charAt(0) >= "4" )/*Navigateurs version 4.XX*/ 

   {
    
	/*var height = screen.availHeight - 20,
        width = screen.availWidth,
	    position;

    if ( navigator.appName.indexOf("Microsoft") >= 0 )//Pour Microsoft Internet Explorer
   
      {
   
	   position = ",left=1,top=1";
   
      }
 
    else//Pour Netscape
   
      {
   
	   position =",screenX=1,screenY=1";
   
      }
   
    win = window.open( url,name,"dependent=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width + position );*/

    win = window.open( url,name,"dependent=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes");

   }

 else
   
   {
    
    win = window.open( url,name,"dependent=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
   
   } 	
 
 win.focus();
 
}

function closeWindow( win, reloadOpenerWindow, reloadParentWindow )

{

 if ( reloadOpenerWindow == null )
   
   {
   
    reloadOpenerWindow = true;

   }

 if ( reloadParentWindow == null )
   
   {
   
    reloadParentWindow = false;

   }

 if ( win.opener != null )
   
   {
   
    if ( !win.opener.closed )
	     
      {
       
	   if ( reloadOpenerWindow )

         {
 
  	      if ( reloadParentWindow )
  	        
		    {
  		     
			 win.opener.parent.location.reload();
  
			}

		  else
			
		    {
		     
			 win.opener.location.reload();

            }

         }
       
	   win.opener.focus();

      }

   }

 win.close();
 
}

function closeWindowAndRedirectOpener( win, url )

{

 if ( win.opener != null )
   
   {
   
    if ( !win.opener.closed )
	     
      {
       
	   if ( url != null && url.length > 0 )

         {
 
  	      win.opener.location = url;

         }
       
	   win.opener.focus();

      }

   }

 win.close();
  
}

function setBackLink( link )

{

 var url = GetCookie( "url" );

 if ( url == null )

   {

    if ( window.opener != null )
      
      {
       
       if ( !window.opener.closed )
         
         {

          url = "javascript:closeWindow( window.top, false );";

         }
       
       else
         
         {
         
          url = "javascript:history.go(-1)";
         
         }

      }

    else   
     
      {
         
       url = "javascript:history.go(-1)";
         
      }

   }
  
 link.href = url;
 
}


function openCenteredWindow( nameWindow, url, width, height )
{
 
 if ( width == null )
   
   {
   
    width = screen.width / 2;

   }

 if ( height == null )
   
   {
   
    height = screen.height / 2;

   }

 var left = ( screen.width / 2 ) - ( width / 2 ),
	 top = ( screen.height / 2 ) - ( height / 2 ),
	 position;
 
 
 if ( navigator.appName.indexOf("Microsoft") >= 0 )//Pour Microsoft Internet Explorer
   
   {
   
    position = ",left=" + left + ",top=" + top;
   
   }
 
 else//Pour Netscape
  
   {
   
	position =",screenX=" + left + ",screenY=" + top;
   
   }

 var win = window.open( url,nameWindow,"status=yes,resizable=yes,width=" + width + ",height=" + height + position );

 win.focus();

}

function openConsoleWindow()
{

 return window.open("","winConsole","resizable=yes,width=400,height=300");

}

function println( msg )
{

 var win = openConsoleWindow();

 win.document.write( msg + "<BR>" );
 
}

function openHiddenWindow( nameWindow, url )
{
 //println( "0 :" + nameWindow );
 openWindow( nameWindow, url, 1, 1, screen.availWidth, screen.availHeight, false );

}

function adjustWindow( win, additionalWidth, additionalHeight )
{
 
 if ( win == null )
   
   {
   
    win = window;

   }
 
 if ( win.opener == null ) // means a main window
   
   {
   
    return; 

   }

 if ( additionalWidth == null )
   
   {
    
	additionalWidth = 0;
   
   }

 if ( additionalHeight == null )
   
   {
    
	additionalHeight = 0;
   
   }

 var width = win.document.body.scrollWidth + MARGIN_WIDTH + additionalWidth,
     height = win.document.body.scrollHeight + MARGIN_HEIGHT + additionalHeight;

 /*println("width=" + width);

 println("height=" + height);*/

 if ( width > screen.availWidth )
   
   {
   
    width = screen.availWidth;

	win.document.body.scroll="yes";

   }

 if ( height > screen.availHeight )
   
   {
   
    height = screen.availHeight;

	win.document.body.scroll="yes";

   }
 
 /*println("width=" + width);

 println("height=" + height);*/

 win.resizeTo( width, height );

 centerWindow( win, width, height );
 
}

function adjustParent( win )
{
 
 if ( win.opener == null ) // means a main window
   
   {
   
    return; 

   }

 var width = 0,
     height = 0;
 
 for( var i = 0 ; i < win.frames.length ; ++i )
   
   {
	
	height += win.frames[i].document.body.scrollHeight + MARGIN_HEIGHT; 

	width += win.frames[i].document.body.scrollWidth + MARGIN_WIDTH;

   }

 if ( width > screen.width )
   
   {
   
    width = screen.width;

	win.document.body.scroll="yes";

   }

 if ( height > screen.height )
   
   {
   
    height = screen.height;

	win.document.body.scroll="yes";

   }

 win.resizeTo( width, height );

 centerWindow( win, width, height );

}

function centerWindow( win, width, height )
{
 
 if ( width == null )
   
   {
   
    width = win.document.body.scrollWidth;

   }

 if ( height == null )
   
   {
   
    height = win.document.body.scrollHeight;

   }
 
 if ( width >= screen.availWidth )
   
   {
   
    width = screen.availWidth;

   }

 if ( height >= screen.availHeight )
   
   {
   
    height = screen.availHeight;

   }

 var left = ( screen.availWidth / 2 ) - ( width / 2 ),
	 top = ( screen.availHeight / 2 ) - ( height / 2 );

 /*println("left = " + left );
 
 println("top = " + top );*/

 win.moveTo( left, top );

}

function getTopOpener( win )
{

 if ( win == null )
   
   {
    
	win = window;
   
   }
 
 for( ; win.opener != null ; win = win.opener ) {}

 return win; 

}

function maximizeWindow( win )
{

 if ( win == null )
   
   {
   
    win = window;

   }

 var aw = screen.availWidth,
     ah = screen.availHeight;

 win.moveTo(0, 0);
 win.resizeTo(aw, ah);

 win.document.body.scroll = "auto";

 /*if (window.screen) 
  
   {
   
	var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
   
   }*/

}

function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	//window.status = printstring;
	return curtop;
}

function closeWindowByName( windowName )
{

 var win;

 win = window.open( "", windowName );

 win.close();

}