/* Test for flash.
 * If flash is on and not set in jsp session update the jsp session on server with value.
 * If flash is off and not set in jsp session reload this page with parameter that updates the jsp session on server with value. 
 * If flash setting has changed from the value set in jsp session reload this page with parameter that updates the jsp session on server with value. 
 */

// Run this from the onload function.
function flashDetection(){

  // Test Flash.
  var jsFlashEnabled = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

  // If bFlashEnabled is not defined in jsp session or bFlashEnabled in jsp session
  // does not have the same value as flash detected here. 
  if (!bFlashEnabledExists || bFlashEnabled != jsFlashEnabled){

    // Reload the page if bFlashEnabled is not in the jsp session and flash is off or
    // bFlashEnabled in jsp session does not have the same value as the flash enabled value detected here.
    if ((!bFlashEnabledExists && !jsFlashEnabled)
                      || bFlashEnabled != jsFlashEnabled){
     // pageURL is set in fluid_detail.jsp

      // If there is no ? already on the URL then this is the first parameter and use ? else &.
      var URLSeparator = (pageURL.indexOf('&') == -1) ? '?' : '&';

      // Add the new value for bFlashEnabled.
      var href = pageURL + URLSeparator + 'bFlashEnabled=' + jsFlashEnabled;

      // Refresh the page.
      window.location.replace(href);
    }else{ // bFlashEnabled is not in the jsp session and flash is on.

      // Update the value on the server with the js detected value.
      var data = {bFlashEnabled: jsFlashEnabled};

      // Do nothing in the callback.
      var callback = function(callbackData){};

      // Send jquery AJAX post.
      // AJAX will not work on ie6 when ActiveX is off, but flash will not work when ActiveX is off.
      // AJAX will work for this case because flash is on.
      $.post(updateSessionURL, data, callback, "text");// BM url form submit syntax.
    }
  }
}
