function openWindow( link, target ) {
   newWindow = window.open( link, target ).focus(); // Make sure the window will come to front
   newWindow.focus(); // Double make sure the window will come to front
   return false;
}

// Flash resize functions
function flashVortexSetFlashWidth( divId, newWidth ) {
   if ( newWidth != null ) { // is this usefull
      document.getElementById( divId ).style.width = newWidth + "px";
   }
}

function flashVortexSetFlashHeight( divId, newHeight ) {
   if ( newHeight != null ) {
      document.getElementById( divId ).style.height = newHeight + "px";
   }
}

// This function is called by the swf movies, parameters cannot be null
function flashVortexSetFlashSize( divId, autoWidth, autoHeight, newWidth, newHeight ) {

   //alert ("This is a Javascript Alert");

   if ( autoWidth == 1 ) {
      flashVortexSetFlashWidth( divId, newWidth );
      // On the download page, if there is a download button
      if ( document.downloadForm ) {
         document.downloadForm.width.value = newWidth;
      }
      // On the download page, if there is a save example button
      if ( document.exampleForm ) {
         document.exampleForm.width.value = newWidth;
      }
      // On the download page, if there is an hosted .swf installation HTML code text area, replace W with new width value
      if ( document.hostedCodeForm ) {
         document.hostedCodeForm.hostedCode.value = document.hostedCodeForm.hostedCode.value.replace( 'W', newWidth );
      }
      // On the download page, if there is a "trouble downloading" link
      if ( $( "a#trbl" ) ) { // Do not name this a#trouble because of weird Firefox 2.0 bug
         var newHref = $( "a#trbl" ).attr( "href" ) + "&width=" + newWidth;
         $( "a#trbl" ).attr( "href", newHref );
      }
      // On the download page, if there is a "Advanced Installation Help" link
      if ( $( "a#installation" ) ) {
         var newHref = $( "a#installation" ).attr( "href" ) + "&width=" + newWidth;
         $( "a#installation" ).attr( "href", newHref );
      }
      // On the download page, if there is an "about this file" section
      if ( $( "#aboutWidth" ) ) {
         $( "#aboutWidth" ).html( newWidth ).append( " px" );
      }
      if ( $( "#aboutEasyHTML" ) ) {
         var newEasy = $( "#aboutEasyHTML" ).text().replace( 'W', newWidth );
         $( "#aboutEasyHTML" ).text( newEasy );
      }
      if ( $( "#aboutAdvancedHTML" ) ) {
         var newAdvanced = $( "#aboutAdvancedHTML" ).text().replace( /{\*swfWidth\*}/g, newWidth );
         $( "#aboutAdvancedHTML" ).text( newAdvanced );
      }
   }
   if ( autoHeight == 1 ) {
      flashVortexSetFlashHeight( divId, newHeight );
      // On the download page, if there is a download button
      if ( document.downloadForm ) {
         document.downloadForm.height.value = newHeight;
      }
      // On the download page, if there is a save example button
      if ( document.exampleForm ) {
         document.exampleForm.height.value = newHeight;
      }
      // On the download page, if there is an hosted .swf installation HTML code text area, replace H with new height value
      if ( document.hostedCodeForm ) {
         document.hostedCodeForm.hostedCode.value = document.hostedCodeForm.hostedCode.value.replace( 'H', newHeight );
      }
      // On the download page, if there is a "trouble downloading" link
      if ( $( "a#trbl" ) ) { // Do not name this a#trouble because of weird Firefox 2.0 bug
         var newHref = $( "a#trbl" ).attr( "href" ) + "&height=" + newHeight;
         $( "a#trbl" ).attr( "href", newHref );
      }
      // On the download page, if there is a "Advanced Installation Help" link
      if ( $( "a#installation" ) ) {
         var newHref = $( "a#installation" ).attr( "href" ) + "&height=" + newHeight;
         $( "a#installation" ).attr( "href", newHref );
      }
      // On the download page if there is an "about this file" section
      if ( $( "#aboutHeight" ) ) {
         $( "#aboutHeight" ).html( newHeight ).append( " px" );
      }
      if ( $( "#aboutEasyHTML" ) ) {
         var newEasy = $( "#aboutEasyHTML" ).text().replace( 'H', newHeight );
         $( "#aboutEasyHTML" ).text( newEasy );
      }
      if ( $( "#aboutAdvancedHTML" ) ) {
         var newAdvanced = $( "#aboutAdvancedHTML" ).text().replace( /{\*swfHeight\*}/g, newHeight );
         $( "#aboutAdvancedHTML" ).text( newAdvanced );
      }
   }
}

function getFlashWidth( divId ) {
   return document.getElementById( divId ).style.width;
}

function getFlashHeight( divId ) {
   return document.getElementById( divId ).style.height;
}

function canResizeFlash() {
   var ua = navigator.userAgent.toLowerCase();
   var opera = ua.indexOf("opera");
   if ( document.getElementById ) {
      if( opera == -1 ) return true;
      else if( parseInt( ua.substr( opera + 6, 1 ) ) >= 7 ) return true;
   }
   return false;
}

function openPopup( page, width, height ) {
   // Hide editor -> was for AS3 editor bug, foreign character feature, needed the animation to be transparent thus bugging the popup
   $( "#editor" ).css( "visibility", "hidden" );
   // Set popup load animation
   $( "#popupContent" ).html( "<div align='center'><img src='images/pixel.png' height='60' /><br/><img src='images/loadingBigLight.gif' /><br/><img src='images/pixel.png' height='20' /><br/><font class='medium'><b>Loading...</b></font></div>" );
   // Load content
   $( "#popupContent" ).load( page, function() {
      if ( $.browser.webkit == true ) $( this ).fadeTo( "fast", 0.99 ). fadeTo( "fast", 1 ) // Chrome 8 bug, doesn't display loaded flash animations
   });
   // Place black background
   $( "#popupBackground" ).width( $( document ).width() )
                .height( $( document ).height() )
                .show()
                .fadeTo( "slow", 0.33 );
   // Compute position
   var x = ( $( window ).width() - width ) / 2;
   var y = $( window ).scrollTop() + ( ( $( window ).height() - height ) / 2 );
   if ( x < 0 ) x = 0;
   if ( y < 0 ) y = 0;
   // Place popup
   $( "#popup" ).css( "left", x + "px" )
                .css( "top", y + "px" )
                .css( "width", width + "px" )
                .css( "height", height + "px" )
                .show();
   $( "#popupContent" ).css( "height", ( height - 50 ) + "px" ); // 48 is height of both close buttons

}

// Make "if content loaded variable"
function closePopup( refresh ) {
   $( "#editor" ).css( "visibility", "visible" );
   $( "#popupContent" ).html( "" );
   $( "#popup" ).hide();
   $( "#popupBackground" ).fadeOut( "slow" );
   if ( refresh == "uploads" ) {
      document["editor"].TGotoLabel( "_level0/swLiveConnect", "refreshUploads" ); // http://www.moock.org/webdesign/flash/fscommand/
   }
}

// Open tool tip
function openToolTip( x, y, width, height, url ) {
   // Display preloader
   $( "#toolTip" ).html( "<img src='images/popupLoad.gif' alt='Loading...' />" );
   // Load content
   $( "#toolTip" ).load( url );
   // Place toolTip
   $( "#toolTip" ).css( "left", x + "px" )
                  .css( "top", y + "px" )
                  .css( "width", width + "px" )
                  .css( "height", height + "px" )
                  .show();   
}

